Introduce a base class for hashes

This commit is contained in:
hashlag
2025-08-09 17:28:53 +03:00
parent f19ea0bc1c
commit 3841242bdb
5 changed files with 37 additions and 12 deletions

21
Chaos/Hashing/Hash.hpp Normal file
View File

@@ -0,0 +1,21 @@
#ifndef CHAOS_HASHING_HASH_HPP
#define CHAOS_HASHING_HASH_HPP
#include <string>
namespace Chaos::Hashing
{
template<typename T>
class Hash
{
public:
std::string ToHexString() const
{
return static_cast<const T &>(*this).ToHexString();
}
};
} // namespace Chaos::Hashing
#endif

View File

@@ -1,11 +1,13 @@
#ifndef CHAOS_MD4HASHER_HPP
#define CHAOS_MD4HASHER_HPP
#ifndef CHAOS_HASHING_MD4HASHER_HPP
#define CHAOS_HASHING_MD4HASHER_HPP
#include <cstdint>
#include <array>
#include <string>
namespace Chaos::Md4
#include "Hash.hpp"
namespace Chaos::Hashing::Md4
{
struct Buffer
@@ -126,7 +128,7 @@ private:
}
};
struct Md4Hash
struct Md4Hash : public Hash<Md4Hash>
{
std::string ToHexString() const
{

View File

@@ -1,11 +1,13 @@
#ifndef CHAOS_MD5HASHER_HPP
#define CHAOS_MD5HASHER_HPP
#ifndef CHAOS_HASHING_MD5HASHER_HPP
#define CHAOS_HASHING_MD5HASHER_HPP
#include <cstdint>
#include <array>
#include <string>
namespace Chaos::Md5
#include "Hash.hpp"
namespace Chaos::Hashing::Md5
{
struct Buffer
@@ -150,7 +152,7 @@ private:
}
};
struct Md5Hash
struct Md5Hash : public Hash<Md5Hash>
{
std::string ToHexString() const
{