Introduce a base class for hashes
This commit is contained in:
21
Chaos/Hashing/Hash.hpp
Normal file
21
Chaos/Hashing/Hash.hpp
Normal 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
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
#ifndef CHAOS_MD4HASHER_HPP
|
#ifndef CHAOS_HASHING_MD4HASHER_HPP
|
||||||
#define CHAOS_MD4HASHER_HPP
|
#define CHAOS_HASHING_MD4HASHER_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Chaos::Md4
|
#include "Hash.hpp"
|
||||||
|
|
||||||
|
namespace Chaos::Hashing::Md4
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Buffer
|
struct Buffer
|
||||||
@@ -126,7 +128,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Md4Hash
|
struct Md4Hash : public Hash<Md4Hash>
|
||||||
{
|
{
|
||||||
std::string ToHexString() const
|
std::string ToHexString() const
|
||||||
{
|
{
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
#ifndef CHAOS_MD5HASHER_HPP
|
#ifndef CHAOS_HASHING_MD5HASHER_HPP
|
||||||
#define CHAOS_MD5HASHER_HPP
|
#define CHAOS_HASHING_MD5HASHER_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Chaos::Md5
|
#include "Hash.hpp"
|
||||||
|
|
||||||
|
namespace Chaos::Hashing::Md5
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Buffer
|
struct Buffer
|
||||||
@@ -150,7 +152,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Md5Hash
|
struct Md5Hash : public Hash<Md5Hash>
|
||||||
{
|
{
|
||||||
std::string ToHexString() const
|
std::string ToHexString() const
|
||||||
{
|
{
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "Md4.hpp"
|
#include "Hashing/Md4.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Md4;
|
using namespace Chaos::Hashing::Md4;
|
||||||
|
|
||||||
TEST(Md4Tests, RFCTest)
|
TEST(Md4Tests, RFCTest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "Md5.hpp"
|
#include "Hashing/Md5.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Md5;
|
using namespace Chaos::Hashing::Md5;
|
||||||
|
|
||||||
TEST(Md5Tests, RFCTest)
|
TEST(Md5Tests, RFCTest)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user