aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/utils
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-01-19 01:29:33 +0100
committerMauro Sardara <msardara@cisco.com>2019-01-21 12:03:48 +0100
commit9e5f41ed6ebe64a789916794626485460078c420 (patch)
treed2ac3090026ec8929558e88eca533f8787a6ff0b /libtransport/src/hicn/transport/utils
parentd13d37534d9449dd54277af664310d5f957dc44a (diff)
- Code style fix
- Improved vpp binary api interface - Correction in object pool destructor - Fix error in Memif Connector Change-Id: Id1dd9219fc1ac0b3717ae019ebff17373bebc635 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/utils')
-rw-r--r--[-rwxr-xr-x]libtransport/src/hicn/transport/utils/identity.cc9
-rw-r--r--[-rwxr-xr-x]libtransport/src/hicn/transport/utils/log.cc8
-rw-r--r--[-rwxr-xr-x]libtransport/src/hicn/transport/utils/log.h4
-rwxr-xr-xlibtransport/src/hicn/transport/utils/object_pool.h11
-rw-r--r--[-rwxr-xr-x]libtransport/src/hicn/transport/utils/signer.cc45
-rw-r--r--[-rwxr-xr-x]libtransport/src/hicn/transport/utils/verifier.cc6
6 files changed, 47 insertions, 36 deletions
diff --git a/libtransport/src/hicn/transport/utils/identity.cc b/libtransport/src/hicn/transport/utils/identity.cc
index bdf7f29f9..1b2fd4828 100755..100644
--- a/libtransport/src/hicn/transport/utils/identity.cc
+++ b/libtransport/src/hicn/transport/utils/identity.cc
@@ -33,10 +33,11 @@ Identity::Identity(const std::string &keystore_name,
parcCryptoSuite_GetSigningAlgorithm(static_cast<PARCCryptoSuite>(suite)),
key_length, validity_days);
- parcAssertTrue(success,
- "parcPkcs12KeyStore_CreateFile('%s', '%s', '%s', %d, %d) failed.",
- keystore_name.c_str(), keystore_password.c_str(),
- subject_name.c_str(), static_cast<int>(key_length), validity_days);
+ parcAssertTrue(
+ success,
+ "parcPkcs12KeyStore_CreateFile('%s', '%s', '%s', %d, %d) failed.",
+ keystore_name.c_str(), keystore_password.c_str(), subject_name.c_str(),
+ static_cast<int>(key_length), validity_days);
PARCIdentityFile *identity_file =
parcIdentityFile_Create(keystore_name.c_str(), keystore_password.c_str());
diff --git a/libtransport/src/hicn/transport/utils/log.cc b/libtransport/src/hicn/transport/utils/log.cc
index 064625ec0..00bd7d54f 100755..100644
--- a/libtransport/src/hicn/transport/utils/log.cc
+++ b/libtransport/src/hicn/transport/utils/log.cc
@@ -25,8 +25,8 @@
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -321,19 +321,19 @@
#include <assert.h>
#include <ctype.h>
+#include <hicn/transport/utils/log.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <hicn/transport/utils/log.h>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
-#include <unistd.h>
#include <sys/time.h>
+#include <unistd.h>
#if defined(__linux__)
#include <linux/limits.h>
#else
diff --git a/libtransport/src/hicn/transport/utils/log.h b/libtransport/src/hicn/transport/utils/log.h
index 17e47e7df..3c4f1277a 100755..100644
--- a/libtransport/src/hicn/transport/utils/log.h
+++ b/libtransport/src/hicn/transport/utils/log.h
@@ -25,8 +25,8 @@
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/src/hicn/transport/utils/object_pool.h
index d4d8e18d6..c369f7e12 100755
--- a/libtransport/src/hicn/transport/utils/object_pool.h
+++ b/libtransport/src/hicn/transport/utils/object_pool.h
@@ -45,7 +45,11 @@ class ObjectPool {
public:
using Ptr = std::unique_ptr<T, ObjectDeleter>;
- ObjectPool() {}
+ ObjectPool() : destructor_(false) {}
+
+ ~ObjectPool() {
+ destructor_ = true;
+ }
std::pair<bool, Ptr> get() {
if (object_pool_.empty()) {
@@ -60,7 +64,9 @@ class ObjectPool {
void add(T *object) {
utils::SpinLock::Acquire locked(object_pool_lock_);
- object_pool_.emplace_back(makePtr(object));
+ if (TRANSPORT_EXPECT_TRUE(!destructor_)) {
+ object_pool_.emplace_back(makePtr(object));
+ }
}
Ptr makePtr(T *object) { return Ptr(object, ObjectDeleter(this)); }
@@ -71,6 +77,7 @@ class ObjectPool {
utils::SpinLock object_pool_lock_;
std::deque<Ptr> object_pool_;
+ bool destructor_;
};
} // namespace utils \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/utils/signer.cc b/libtransport/src/hicn/transport/utils/signer.cc
index c11d5e183..579b08aff 100755..100644
--- a/libtransport/src/hicn/transport/utils/signer.cc
+++ b/libtransport/src/hicn/transport/utils/signer.cc
@@ -17,10 +17,9 @@
#include <hicn/transport/errors/malformed_ahpacket_exception.h>
#include <hicn/transport/utils/endianess.h>
+#include <hicn/transport/utils/key_id.h>
#include <hicn/transport/utils/membuf.h>
#include <hicn/transport/utils/signer.h>
-#include <hicn/transport/utils/key_id.h>
-
extern "C" {
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
@@ -77,7 +76,7 @@ Signer::~Signer() {
void Signer::sign(Packet &packet) {
// header chain points to the IP + TCP hicn header
utils::MemBuf *header_chain = packet.header_head_;
- utils::MemBuf * payload_chain = packet.payload_head_;
+ utils::MemBuf *payload_chain = packet.payload_head_;
uint8_t *hicn_packet = header_chain->writableData();
Packet::Format format = packet.getFormat();
std::size_t sign_len_bytes = parcSigner_GetSignatureSize(signer_);
@@ -101,46 +100,51 @@ void Signer::sign(Packet &packet) {
/* Fill the hicn_ah header */
using namespace std::chrono;
- auto now = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
+ auto now = duration_cast<milliseconds>(system_clock::now().time_since_epoch())
+ .count();
packet.setSignatureTimestamp(now);
// *reinterpret_cast<uint64_t*>(ah->signTime) = utils::hton<uint64_t>(now);
- // // std::memcpy(&ah->hicn_ah.signTime, &sign_time, sizeof(ah->hicn_ah.signTime));
+ // // std::memcpy(&ah->hicn_ah.signTime, &sign_time,
+ // sizeof(ah->hicn_ah.signTime));
- packet.setValidationAlgorithm(CryptoSuite(parcSigner_GetCryptoSuite(this->signer_)));
+ packet.setValidationAlgorithm(
+ CryptoSuite(parcSigner_GetCryptoSuite(this->signer_)));
// ah->validationAlgorithm = parcSigner_GetCryptoSuite(this->signer_);
KeyId key_id;
- key_id.first = (uint8_t *)parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_), 0);
+ key_id.first = (uint8_t *)parcBuffer_Overlay(
+ (PARCBuffer *)parcKeyId_GetKeyId(this->key_id_), 0);
packet.setKeyId(key_id);
// memcpy(ah->keyId,
- // parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_), 0),
- // sizeof(_ah_header_t::keyId));
+ // parcBuffer_Overlay((PARCBuffer *) parcKeyId_GetKeyId(this->key_id_),
+ // 0), sizeof(_ah_header_t::keyId));
// Calculate hash
utils::CryptoHasher hasher(parcSigner_GetCryptoHasher(signer_));
hasher.init();
hasher.updateBytes(hicn_packet, header_len);
hasher.updateBytes(zeros, sign_len_bytes);
-
- for (utils::MemBuf *current = payload_chain; current != header_chain; current = current->next()) {
+
+ for (utils::MemBuf *current = payload_chain; current != header_chain;
+ current = current->next()) {
hasher.updateBytes(current->data(), current->length());
}
utils::CryptoHash hash = hasher.finalize();
-
+
PARCSignature *signature = parcSigner_SignDigest(this->signer_, hash.hash_);
PARCBuffer *buffer = parcSignature_GetSignature(signature);
- PARCByteArray * byte_array = parcBuffer_Array(buffer);
- uint8_t * bytes = parcByteArray_Array(byte_array);
+ PARCByteArray *byte_array = parcBuffer_Array(buffer);
+ uint8_t *bytes = parcByteArray_Array(byte_array);
size_t bytes_len = parcBuffer_Remaining(buffer);
if (bytes_len > sign_len_bytes) {
throw errors::MalformedAHPacketException();
}
- /* Restore the resetted fields */
+ /* Restore the resetted fields */
if (format & HFO_INET) {
memcpy(hicn_packet, &header_copy, sizeof(hicn_v4_hdr_t));
} else if (format & HFO_INET6) {
@@ -151,12 +155,11 @@ void Signer::sign(Packet &packet) {
std::unique_ptr<utils::MemBuf> signature_buffer;
std::unique_ptr<utils::MemBuf> tmp_buf = utils::MemBuf::takeOwnership(
- bytes,
- bytes_len,
- bytes_len,
- [](void* buf, void* userData){ parcSignature_Release((PARCSignature **)&userData); },
- signature,
- true);
+ bytes, bytes_len, bytes_len,
+ [](void *buf, void *userData) {
+ parcSignature_Release((PARCSignature **)&userData);
+ },
+ signature, true);
if (offset) {
signature_buffer = utils::MemBuf::create(offset);
diff --git a/libtransport/src/hicn/transport/utils/verifier.cc b/libtransport/src/hicn/transport/utils/verifier.cc
index 9a3de43c1..93efe063a 100755..100644
--- a/libtransport/src/hicn/transport/utils/verifier.cc
+++ b/libtransport/src/hicn/transport/utils/verifier.cc
@@ -65,9 +65,9 @@ bool Verifier::addKey(PARCKey *key) {
return true;
}
-PARCKeyId * Verifier::addKeyFromCertificate(const std::string &file_name) {
- PARCCertificateFactory *factory = parcCertificateFactory_Create(PARCCertificateType_X509,
- PARCContainerEncoding_PEM);
+PARCKeyId *Verifier::addKeyFromCertificate(const std::string &file_name) {
+ PARCCertificateFactory *factory = parcCertificateFactory_Create(
+ PARCCertificateType_X509, PARCContainerEncoding_PEM);
parcAssertNotNull(factory, "Expected non-NULL factory");
if (!file_exists(file_name)) {