From 3c532dd5e1844e0f094e2ae7555b1f65a2fd106f Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Thu, 27 Feb 2020 15:22:51 +0100 Subject: [HICN-538] Use type utils::CryptoHashtype instead of HashAlgorithm everywhere Change-Id: Iddbc427611c888b28059170a70c0925ebb299cb5 Signed-off-by: Mauro Sardara --- libtransport/includes/hicn/transport/core/packet.h | 3 ++- .../includes/hicn/transport/interfaces/socket_producer.h | 5 +++-- libtransport/includes/hicn/transport/security/identity.h | 6 ++---- libtransport/src/core/manifest.h | 6 +++--- libtransport/src/core/manifest_format.h | 10 ++-------- libtransport/src/core/manifest_format_fixed.cc | 6 +++--- libtransport/src/core/manifest_format_fixed.h | 4 ++-- libtransport/src/core/manifest_inline.h | 2 +- libtransport/src/core/packet.cc | 2 +- libtransport/src/implementation/p2psecure_socket_producer.cc | 2 +- libtransport/src/implementation/p2psecure_socket_producer.h | 2 +- libtransport/src/implementation/socket_producer.h | 10 +++++----- libtransport/src/interfaces/socket_producer.cc | 6 +++--- libtransport/src/protocols/manifest_incremental_indexer.h | 2 +- libtransport/src/security/identity.cc | 2 +- 15 files changed, 31 insertions(+), 37 deletions(-) (limited to 'libtransport') diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index e80912cbe..e758aa13e 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -149,7 +149,8 @@ class Packet : public std::enable_shared_from_this { utils::KeyId getKeyId() const; - virtual utils::CryptoHash computeDigest(HashAlgorithm algorithm) const; + virtual utils::CryptoHash computeDigest( + utils::CryptoHashType algorithm) const; void setChecksum(); diff --git a/libtransport/includes/hicn/transport/interfaces/socket_producer.h b/libtransport/includes/hicn/transport/interfaces/socket_producer.h index e4823cb5c..2dc289995 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.h @@ -101,7 +101,8 @@ class ProducerSocket { int setSocketOption(int socket_option_key, ProducerContentCallback socket_option_value); - int setSocketOption(int socket_option_key, HashAlgorithm socket_option_value); + int setSocketOption(int socket_option_key, + utils::CryptoHashType socket_option_value); int setSocketOption(int socket_option_key, utils::CryptoSuite socket_option_value); @@ -130,7 +131,7 @@ class ProducerSocket { ProducerInterestCallback **socket_option_value); int getSocketOption(int socket_option_key, - HashAlgorithm &socket_option_value); + utils::CryptoHashType &socket_option_value); int getSocketOption(int socket_option_key, utils::CryptoSuite &socket_option_value); diff --git a/libtransport/includes/hicn/transport/security/identity.h b/libtransport/includes/hicn/transport/security/identity.h index c5d4b975d..a575af134 100644 --- a/libtransport/includes/hicn/transport/security/identity.h +++ b/libtransport/includes/hicn/transport/security/identity.h @@ -18,8 +18,6 @@ #include #include -#include - extern "C" { #include #include @@ -40,7 +38,7 @@ class Identity { Identity(const Identity &other); Identity(std::string &file_name, std::string &password, - transport::core::HashAlgorithm hash_algorithm); + utils::CryptoHashType hash_algorithm); ~Identity(); @@ -57,7 +55,7 @@ class Identity { private: PARCIdentity *identity_; std::shared_ptr signer_; - transport::core::HashAlgorithm hash_algorithm_; + utils::CryptoHashType hash_algorithm_; }; } // namespace utils diff --git a/libtransport/src/core/manifest.h b/libtransport/src/core/manifest.h index b4875bf22..eadfed752 100644 --- a/libtransport/src/core/manifest.h +++ b/libtransport/src/core/manifest.h @@ -96,13 +96,13 @@ class Manifest : public Base { return *this; } - Manifest &setHashAlgorithm(HashAlgorithm hash_algorithm) { + Manifest &setHashAlgorithm(utils::CryptoHashType hash_algorithm) { hash_algorithm_ = hash_algorithm; encoder_.setHashAlgorithm(hash_algorithm_); return *this; } - HashAlgorithm getHashAlgorithm() { return hash_algorithm_; } + utils::CryptoHashType getHashAlgorithm() { return hash_algorithm_; } ManifestType getManifestType() const { return manifest_type_; } @@ -138,7 +138,7 @@ class Manifest : public Base { protected: ManifestType manifest_type_; - HashAlgorithm hash_algorithm_; + utils::CryptoHashType hash_algorithm_; bool is_last_; Encoder encoder_; diff --git a/libtransport/src/core/manifest_format.h b/libtransport/src/core/manifest_format.h index f95d19aa8..36d23f99b 100644 --- a/libtransport/src/core/manifest_format.h +++ b/libtransport/src/core/manifest_format.h @@ -45,12 +45,6 @@ enum class ManifestType : uint8_t { FLIC_MANIFEST = 3, }; -enum class HashAlgorithm : uint8_t { - SHA_256 = static_cast(utils::CryptoHashType::SHA_256), - SHA_512 = static_cast(utils::CryptoHashType::SHA_512), - CRC32C = static_cast(utils::CryptoHashType::CRC32C), -}; - /** * INCREMENTAL: Manifests will be received inline with the data with no specific * assumption regarding the manifest capacity. Consumers can send interests @@ -92,7 +86,7 @@ class ManifestEncoder { return static_cast(*this).setManifestTypeImpl(type); } - ManifestEncoder &setHashAlgorithm(HashAlgorithm hash) { + ManifestEncoder &setHashAlgorithm(utils::CryptoHashType hash) { return static_cast(*this).setHashAlgorithmImpl(hash); } @@ -166,7 +160,7 @@ class ManifestDecoder { return static_cast(*this).getManifestTypeImpl(); } - HashAlgorithm getHashAlgorithm() const { + utils::CryptoHashType getHashAlgorithm() const { return static_cast(*this).getHashAlgorithmImpl(); } diff --git a/libtransport/src/core/manifest_format_fixed.cc b/libtransport/src/core/manifest_format_fixed.cc index 4073a5d26..ca80c38b1 100644 --- a/libtransport/src/core/manifest_format_fixed.cc +++ b/libtransport/src/core/manifest_format_fixed.cc @@ -55,7 +55,7 @@ FixedManifestEncoder &FixedManifestEncoder::clearImpl() { } FixedManifestEncoder &FixedManifestEncoder::setHashAlgorithmImpl( - HashAlgorithm algorithm) { + utils::CryptoHashType algorithm) { manifest_header_->hash_algorithm = static_cast(algorithm); return *this; } @@ -170,8 +170,8 @@ ManifestType FixedManifestDecoder::getManifestTypeImpl() const { return static_cast(manifest_header_->manifest_type); } -HashAlgorithm FixedManifestDecoder::getHashAlgorithmImpl() const { - return static_cast(manifest_header_->hash_algorithm); +utils::CryptoHashType FixedManifestDecoder::getHashAlgorithmImpl() const { + return static_cast(manifest_header_->hash_algorithm); } NextSegmentCalculationStrategy diff --git a/libtransport/src/core/manifest_format_fixed.h b/libtransport/src/core/manifest_format_fixed.h index 9cacb3bc2..1d7cd7d32 100644 --- a/libtransport/src/core/manifest_format_fixed.h +++ b/libtransport/src/core/manifest_format_fixed.h @@ -94,7 +94,7 @@ class FixedManifestEncoder : public ManifestEncoder { FixedManifestEncoder &setManifestTypeImpl(ManifestType manifest_type); - FixedManifestEncoder &setHashAlgorithmImpl(HashAlgorithm algorithm); + FixedManifestEncoder &setHashAlgorithmImpl(utils::CryptoHashType algorithm); FixedManifestEncoder &setNextSegmentCalculationStrategyImpl( NextSegmentCalculationStrategy strategy); @@ -144,7 +144,7 @@ class FixedManifestDecoder : public ManifestDecoder { ManifestType getManifestTypeImpl() const; - HashAlgorithm getHashAlgorithmImpl() const; + utils::CryptoHashType getHashAlgorithmImpl() const; NextSegmentCalculationStrategy getNextSegmentCalculationStrategyImpl() const; diff --git a/libtransport/src/core/manifest_inline.h b/libtransport/src/core/manifest_inline.h index 235c6f3a0..0227fa93a 100644 --- a/libtransport/src/core/manifest_inline.h +++ b/libtransport/src/core/manifest_inline.h @@ -44,7 +44,7 @@ class ManifestInline static TRANSPORT_ALWAYS_INLINE ManifestInline *createManifest( const core::Name &manifest_name, ManifestVersion version, - ManifestType type, HashAlgorithm algorithm, bool is_last, + ManifestType type, utils::CryptoHashType algorithm, bool is_last, const Name &base_name, NextSegmentCalculationStrategy strategy, std::size_t signature_size) { auto manifest = new ManifestInline(manifest_name, signature_size); diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 817f8de66..67e647fca 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -344,7 +344,7 @@ utils::KeyId Packet::getKeyId() const { return return_value; } -utils::CryptoHash Packet::computeDigest(HashAlgorithm algorithm) const { +utils::CryptoHash Packet::computeDigest(utils::CryptoHashType algorithm) const { utils::CryptoHasher hasher(static_cast(algorithm)); hasher.init(); diff --git a/libtransport/src/implementation/p2psecure_socket_producer.cc b/libtransport/src/implementation/p2psecure_socket_producer.cc index d7161986b..d0852539a 100644 --- a/libtransport/src/implementation/p2psecure_socket_producer.cc +++ b/libtransport/src/implementation/p2psecure_socket_producer.cc @@ -367,7 +367,7 @@ int P2PSecureProducerSocket::setSocketOption( } int P2PSecureProducerSocket::setSocketOption( - int socket_option_key, HashAlgorithm socket_option_value) { + int socket_option_key, utils::CryptoHashType socket_option_value) { if (!list_secure_producers.empty()) for (auto it = list_secure_producers.cbegin(); it != list_secure_producers.cend(); it++) diff --git a/libtransport/src/implementation/p2psecure_socket_producer.h b/libtransport/src/implementation/p2psecure_socket_producer.h index c2cbf31ac..33339deba 100644 --- a/libtransport/src/implementation/p2psecure_socket_producer.h +++ b/libtransport/src/implementation/p2psecure_socket_producer.h @@ -84,7 +84,7 @@ class P2PSecureProducerSocket : public ProducerSocket { ProducerContentCallback socket_option_value) override; int setSocketOption(int socket_option_key, - HashAlgorithm socket_option_value) override; + utils::CryptoHashType socket_option_value) override; int setSocketOption(int socket_option_key, utils::CryptoSuite socket_option_value) override; diff --git a/libtransport/src/implementation/socket_producer.h b/libtransport/src/implementation/socket_producer.h index 1f03fe53d..54fca4fdf 100644 --- a/libtransport/src/implementation/socket_producer.h +++ b/libtransport/src/implementation/socket_producer.h @@ -53,7 +53,7 @@ class ProducerSocket : public Socket, async_thread_(), registration_status_(REGISTRATION_NOT_ATTEMPTED), making_manifest_(false), - hash_algorithm_(HashAlgorithm::SHA_256), + hash_algorithm_(utils::CryptoHashType::SHA_256), suffix_strategy_(core::NextSegmentCalculationStrategy::INCREMENTAL), on_interest_input_(VOID_HANDLER), on_interest_dropped_input_buffer_(VOID_HANDLER), @@ -108,7 +108,7 @@ class ProducerSocket : public Socket, // during the production std::size_t data_packet_size = data_packet_size_; uint32_t content_object_expiry_time = content_object_expiry_time_; - HashAlgorithm hash_algo = hash_algorithm_; + utils::CryptoHashType hash_algo = hash_algorithm_; bool making_manifest = making_manifest_; auto suffix_strategy = utils::SuffixStrategyFactory::getSuffixStrategy( suffix_strategy_, start_offset); @@ -648,7 +648,7 @@ class ProducerSocket : public Socket, } virtual int setSocketOption(int socket_option_key, - HashAlgorithm socket_option_value) { + utils::CryptoHashType socket_option_value) { switch (socket_option_key) { case GeneralTransportOptions::HASH_ALGORITHM: hash_algorithm_ = socket_option_value; @@ -848,7 +848,7 @@ class ProducerSocket : public Socket, } virtual int getSocketOption(int socket_option_key, - HashAlgorithm &socket_option_value) { + utils::CryptoHashType &socket_option_value) { switch (socket_option_key) { case GeneralTransportOptions::HASH_ALGORITHM: socket_option_value = hash_algorithm_; @@ -983,7 +983,7 @@ class ProducerSocket : public Socket, // function std::unordered_map> seq_number_map_; - std::atomic hash_algorithm_; + std::atomic hash_algorithm_; std::atomic crypto_suite_; utils::SpinLock signer_lock_; std::shared_ptr signer_; diff --git a/libtransport/src/interfaces/socket_producer.cc b/libtransport/src/interfaces/socket_producer.cc index 679f7ccf4..d030fe756 100644 --- a/libtransport/src/interfaces/socket_producer.cc +++ b/libtransport/src/interfaces/socket_producer.cc @@ -126,7 +126,7 @@ int ProducerSocket::setSocketOption( } int ProducerSocket::setSocketOption(int socket_option_key, - HashAlgorithm socket_option_value) { + utils::CryptoHashType socket_option_value) { return socket_->setSocketOption(socket_option_key, socket_option_value); } @@ -177,8 +177,8 @@ int ProducerSocket::getSocketOption( return socket_->getSocketOption(socket_option_key, socket_option_value); } -int ProducerSocket::getSocketOption(int socket_option_key, - HashAlgorithm &socket_option_value) { +int ProducerSocket::getSocketOption( + int socket_option_key, utils::CryptoHashType &socket_option_value) { return socket_->getSocketOption(socket_option_key, socket_option_value); } diff --git a/libtransport/src/protocols/manifest_incremental_indexer.h b/libtransport/src/protocols/manifest_incremental_indexer.h index 88ae1720b..38b01533e 100644 --- a/libtransport/src/protocols/manifest_incremental_indexer.h +++ b/libtransport/src/protocols/manifest_incremental_indexer.h @@ -30,7 +30,7 @@ class ManifestIncrementalIndexer : public IncrementalIndexer { public: using SuffixQueue = std::queue; - using HashEntry = std::pair, core::HashAlgorithm>; + using HashEntry = std::pair, utils::CryptoHashType>; ManifestIncrementalIndexer(implementation::ConsumerSocket *icn_socket, TransportProtocol *transport, diff --git a/libtransport/src/security/identity.cc b/libtransport/src/security/identity.cc index 55713245e..d7a08f7b5 100644 --- a/libtransport/src/security/identity.cc +++ b/libtransport/src/security/identity.cc @@ -73,7 +73,7 @@ Identity Identity::generateIdentity(const std::string &subject_name) { } Identity::Identity(std::string &file_name, std::string &password, - transport::core::HashAlgorithm hash_algorithm) + utils::CryptoHashType hash_algorithm) : hash_algorithm_(hash_algorithm) { parcSecurity_Init(); -- cgit 1.2.3-korg