aboutsummaryrefslogtreecommitdiff
path: root/src/common/Cryptography/HMAC.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Cryptography/HMAC.h')
-rw-r--r--src/common/Cryptography/HMAC.h43
1 files changed, 10 insertions, 33 deletions
diff --git a/src/common/Cryptography/HMAC.h b/src/common/Cryptography/HMAC.h
index 6b9d2a081bd..7925fb23a61 100644
--- a/src/common/Cryptography/HMAC.h
+++ b/src/common/Cryptography/HMAC.h
@@ -23,15 +23,12 @@
#include "Errors.h"
#include <array>
#include <string>
-//#include <string_view>
+#include <string_view>
#include <openssl/hmac.h>
-#include "advstd.h"
class BigNumber;
-namespace Trinity
-{
-namespace Impl
+namespace Trinity::Impl
{
struct HMACImpl
{
@@ -72,26 +69,11 @@ namespace Impl
return hash.GetDigest();
}
- private: // c++17
- template <typename T>
- static void UpdateData_OLDCPP(GenericHMAC& hash, T const& data)
- {
- hash.UpdateData(data);
- }
-
- template <typename T, typename... TRest>
- static void UpdateData_OLDCPP(GenericHMAC& hash, T const& data, TRest&&... rest)
- {
- hash.UpdateData(data);
- UpdateData_OLDCPP(hash, std::forward<TRest>(rest)...);
- }
-
- public:
template <typename Container, typename... Ts>
- static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t<advstd::conjunction<advstd::negation<std::is_integral<Ts>>...>::value, Digest>
+ static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, Digest>
{
GenericHMAC hash(seed);
- UpdateData_OLDCPP(hash, std::forward<Ts>(pack)...);
+ (hash.UpdateData(std::forward<Ts>(pack)), ...);
hash.Finalize();
return hash.GetDigest();
}
@@ -102,7 +84,7 @@ namespace Impl
ASSERT(result == 1);
}
template <typename Container>
- GenericHMAC(Container const& container) : GenericHMAC(container.data(), container.size()) {}
+ GenericHMAC(Container const& container) : GenericHMAC(std::data(container), std::size(container)) {}
~GenericHMAC()
{
@@ -117,11 +99,11 @@ namespace Impl
int result = HMAC_Update(_ctx, data, len);
ASSERT(result == 1);
}
- // c++17 void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
- void UpdateData(std::string const& str) { UpdateData(str.c_str()); } /* explicit overload to avoid using the container template */
- void UpdateData(char const* str) { UpdateData(reinterpret_cast<uint8 const*>(str), strlen(str)); } /* explicit overload to avoid using the container template */
+ void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
+ void UpdateData(std::string const& str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
+ void UpdateData(char const* str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
template <typename Container>
- void UpdateData(Container const& c) { UpdateData(advstd::data(c), advstd::size(c)); }
+ void UpdateData(Container const& c) { UpdateData(std::data(c), std::size(c)); }
void Finalize()
{
@@ -139,15 +121,10 @@ namespace Impl
Digest _digest = { };
};
}
-}
-namespace Trinity
-{
-namespace Crypto
+namespace Trinity::Crypto
{
using HMAC_SHA1 = Trinity::Impl::GenericHMAC<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
using HMAC_SHA256 = Trinity::Impl::GenericHMAC<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
}
-}
-
#endif