size_t get_size(const SecuredMessage& message) { size_t size = sizeof(uint8_t); // protocol version size += get_size(message.header_fields); size += length_coding_size(get_size(message.header_fields)); size += get_size(message.trailer_fields); size += length_coding_size(get_size(message.trailer_fields)); size += get_size(message.payload); return size; }
size_t get_size(const Certificate& cert) { size_t size = sizeof(cert.version()); size += get_size(cert.signer_info); size += get_size(cert.subject_info); size += get_size(cert.subject_attributes); size += length_coding_size(get_size(cert.subject_attributes)); size += get_size(cert.validity_restriction); size += length_coding_size(get_size(cert.validity_restriction)); size += get_size(cert.signature); return size; }
size_t deserialize(InputArchive& ar, SecuredMessage& message) { uint8_t protocol_version = 0; ar >> protocol_version; size_t length = sizeof(protocol_version); if (protocol_version == 2) { const size_t hdr_length = deserialize(ar, message.header_fields); length += hdr_length + length_coding_size(hdr_length); length += deserialize(ar, message.payload); const size_t trlr_length = deserialize(ar, message.trailer_fields); length += trlr_length + length_coding_size(trlr_length); } else { throw deserialization_error("Unsupported SecuredMessage protocol version"); } return length; }
size_t get_size(const Payload& payload) { size_t length = sizeof(PayloadType); const size_t data = size(payload.data, OsiLayer::Network, max_osi_layer()); length += data; length += length_coding_size(data); return length; }
size_t deserialize(InputArchive& ar, Certificate& cert) { uint8_t version = 0; deserialize(ar, version); size_t size = sizeof(cert.version()); if (2 == version) { size += deserialize(ar, cert.signer_info); size += deserialize(ar, cert.subject_info); size += deserialize(ar, cert.subject_attributes); size += length_coding_size(get_size(cert.subject_attributes)); size += deserialize(ar, cert.validity_restriction); size += length_coding_size(get_size(cert.validity_restriction)); size += deserialize(ar, cert.signature); } else { throw deserialization_error("Unsupported Certificate version"); } return size; }
size_t deserialize(InputArchive& ar, Payload& payload) { size_t size = sizeof(PayloadType); PayloadType type; deserialize(ar, type); payload.type = type; const auto data_length = deserialize_length(ar); size += length_coding_size(data_length); size += data_length; ByteBuffer buf(data_length); ar.load_binary(buf.data(), buf.size()); payload.data = CohesivePacket(std::move(buf), OsiLayer::Network); return size; }
size_t get_size(const ByteBuffer& buf) { size_t size = buf.size(); size += length_coding_size(size); return size; }