From 08233d44a6cfde878d7e10bca38ae935ed1c8fd5 Mon Sep 17 00:00:00 2001 From: Mauro Date: Wed, 30 Jun 2021 07:57:22 +0000 Subject: [HICN-713] Transport Library Major Refactoring 2 Co-authored-by: Luca Muscariello Co-authored-by: Michele Papalini Co-authored-by: Olivier Roques Co-authored-by: Giulio Grassi Signed-off-by: Mauro Sardara Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2 --- libtransport/src/core/packet.cc | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'libtransport/src/core/packet.cc') diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 6f237729a..51337201f 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -13,10 +13,11 @@ * limitations under the License. */ +#include +#include #include #include #include -#include extern "C" { #ifndef _WIN32 @@ -250,7 +251,7 @@ Packet::Format Packet::getFormat() const { */ if (format_ == HF_UNSPEC && length()) { if (hicn_packet_get_format(packet_start_, &format_) < 0) { - TRANSPORT_LOGE("Unexpected packet format."); + LOG(ERROR) << "Unexpected packet format HF_UNSPEC."; } } @@ -262,12 +263,12 @@ std::shared_ptr Packet::acquireMemBufReference() { } void Packet::dump() const { - TRANSPORT_LOGI("HEADER -- Length: %zu", headerSize()); - TRANSPORT_LOGI("PAYLOAD -- Length: %zu", payloadSize()); + LOG(INFO) << "HEADER -- Length: " << headerSize(); + LOG(INFO) << "PAYLOAD -- Length: " << payloadSize(); const utils::MemBuf *current = this; do { - TRANSPORT_LOGI("MemBuf Length: %zu", current->length()); + LOG(INFO) << "MemBuf Length: " << current->length(); dump((uint8_t *)current->data(), current->length()); current = current->next(); } while (current != this); @@ -289,6 +290,19 @@ void Packet::setSignatureSize(std::size_t size_bytes) { } } +void Packet::setSignatureSizeGap(std::size_t size_bytes) { + if (!authenticationHeader()) { + throw errors::RuntimeException("Packet without Authentication Header."); + } + + int ret = hicn_packet_set_signature_gap(format_, packet_start_, + (uint8_t)size_bytes); + + if (ret < 0) { + throw errors::RuntimeException("Error setting signature size."); + } +} + uint8_t *Packet::getSignature() const { if (!authenticationHeader()) { throw errors::RuntimeException("Packet without Authentication Header."); @@ -392,8 +406,8 @@ auth::KeyId Packet::getKeyId() const { } auth::CryptoHash Packet::computeDigest(auth::CryptoHashType algorithm) const { - auth::CryptoHasher hasher(static_cast(algorithm)); - hasher.init(); + auth::CryptoHash hash; + hash.setType(algorithm); // Copy IP+TCP/ICMP header before zeroing them hicn_header_t header_copy; @@ -402,15 +416,10 @@ auth::CryptoHash Packet::computeDigest(auth::CryptoHashType algorithm) const { const_cast(this)->resetForHash(); - const utils::MemBuf *current = this; - do { - hasher.updateBytes(current->data(), current->length()); - current = current->next(); - } while (current != this); - + hash.computeDigest(this); hicn_packet_copy_header(format_, &header_copy, packet_start_, false); - return hasher.finalize(); + return hash; } bool Packet::checkIntegrity() const { -- cgit 1.2.3-korg