diff --git a/Chaos/Hash/Hasher.hpp b/Chaos/Hash/Hasher.hpp index 796c02f..778bea5 100644 --- a/Chaos/Hash/Hasher.hpp +++ b/Chaos/Hash/Hasher.hpp @@ -1,42 +1,19 @@ #ifndef CHAOS_HASH_HASHER_HPP #define CHAOS_HASH_HASHER_HPP +#include + +#include "Hash.hpp" + namespace Chaos::Hash { template -class Hasher +concept Hasher = requires(T hasher, uint8_t * begin, uint8_t * end) { -public: - void Reset() - { - Impl().Reset(); - } - - template - void Update(InputIt begin, InputIt end) - { - Impl().Update(begin, end); - } - - auto Finish() - { - return Impl().Finish(); - } - -protected: - Hasher() = default; - -private: - const T & Impl() const - { - return static_cast(*this); - } - - T & Impl() - { - return static_cast(*this); - } + hasher.Reset(); + hasher.Update(begin, end); + { hasher.Finish() } -> Hash; }; } // namespace Chaos::Hash diff --git a/Chaos/Hash/Md4.hpp b/Chaos/Hash/Md4.hpp index d6528d5..e78dec3 100644 --- a/Chaos/Hash/Md4.hpp +++ b/Chaos/Hash/Md4.hpp @@ -163,7 +163,7 @@ struct Md4Hash static_assert(Hash); -class Md4Hasher : public Hasher +class Md4Hasher { public: using HashType = Md4Hash; @@ -304,6 +304,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Md4 #endif // CHAOS_HASH_MD4_HPP diff --git a/Chaos/Hash/Md5.hpp b/Chaos/Hash/Md5.hpp index ecdb288..cb1be91 100644 --- a/Chaos/Hash/Md5.hpp +++ b/Chaos/Hash/Md5.hpp @@ -187,7 +187,7 @@ struct Md5Hash static_assert(Hash); -class Md5Hasher : public Hasher +class Md5Hasher { public: using HashType = Md5Hash; @@ -328,6 +328,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Md5 #endif // CHAOS_HASH_MD5_HPP diff --git a/Chaos/Hash/Sha1.hpp b/Chaos/Hash/Sha1.hpp index ee99e83..ad743d8 100644 --- a/Chaos/Hash/Sha1.hpp +++ b/Chaos/Hash/Sha1.hpp @@ -157,7 +157,7 @@ struct Sha1Hash static_assert(Hash); -class Sha1Hasher : public Hasher +class Sha1Hasher { public: using HashType = Sha1Hash; @@ -298,6 +298,8 @@ private: } }; +static_assert(Hasher); + } // namespace Chaos::Hash::Sha1 #endif // CHAOS_HASH_SHA1_HPP diff --git a/Chaos/Mac/Hmac.hpp b/Chaos/Mac/Hmac.hpp index 125bb3a..82ecc7e 100644 --- a/Chaos/Mac/Hmac.hpp +++ b/Chaos/Mac/Hmac.hpp @@ -3,7 +3,6 @@ #include #include -#include #include "Hash/Hasher.hpp" #include "Service/ChaosException.hpp" @@ -11,8 +10,7 @@ namespace Chaos::Mac::Hmac { -template, HasherImpl>>> +template class Hmac { public: