Introduce a base class for hashers
This commit is contained in:
25
Chaos/Hashing/Hasher.hpp
Normal file
25
Chaos/Hashing/Hasher.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef CHAOS_HASHING_HASHER_HPP
|
||||||
|
#define CHAOS_HASHING_HASHER_HPP
|
||||||
|
|
||||||
|
namespace Chaos::Hashing
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Hasher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename InputIt>
|
||||||
|
void Update(InputIt begin, InputIt end)
|
||||||
|
{
|
||||||
|
static_cast<T &>(*this).Update(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Finish()
|
||||||
|
{
|
||||||
|
return static_cast<T &>(*this).Finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Chaos::Hashing
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Hash.hpp"
|
#include "Hash.hpp"
|
||||||
|
#include "Hasher.hpp"
|
||||||
|
|
||||||
namespace Chaos::Hashing::Md4
|
namespace Chaos::Hashing::Md4
|
||||||
{
|
{
|
||||||
@@ -148,7 +149,7 @@ struct Md4Hash : public Hash<Md4Hash>
|
|||||||
std::array<uint8_t, 16> RawDigest;
|
std::array<uint8_t, 16> RawDigest;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Md4Hasher
|
class Md4Hasher : public Hasher<Md4Hasher>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Md4Hasher()
|
Md4Hasher()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Hash.hpp"
|
#include "Hash.hpp"
|
||||||
|
#include "Hasher.hpp"
|
||||||
|
|
||||||
namespace Chaos::Hashing::Md5
|
namespace Chaos::Hashing::Md5
|
||||||
{
|
{
|
||||||
@@ -172,7 +173,7 @@ struct Md5Hash : public Hash<Md5Hash>
|
|||||||
std::array<uint8_t, 16> RawDigest;
|
std::array<uint8_t, 16> RawDigest;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Md5Hasher
|
class Md5Hasher : public Hasher<Md5Hasher>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Md5Hasher()
|
Md5Hasher()
|
||||||
|
|||||||
Reference in New Issue
Block a user