3 #ifndef DATA_DEDUPLICATION_SERVICE_HASHUTILS_H
4 #define DATA_DEDUPLICATION_SERVICE_HASHUTILS_H
12 #include <openssl/core.h>
13 #include <openssl/sha.h>
14 #include <openssl/md5.h>
15 #include <openssl/md4.h>
16 #include <openssl/md2.h>
17 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
21 constexpr std::array<
unsigned char *(*)(
const unsigned char *d,
size_t n,
unsigned char *md), 6>
funcs
23 &MD5, &SHA384, &SHA512,&MD4};
42 template<hash_function hash = MD_5>
43 std::string
getHashStr(std::string_view stringView);
48 static constexpr std::array<unsigned short, 6> hashFunctionSize
61 static constexpr std::array<const char *, 6> hashFunctionName
86 template<hash_function hash>
88 unsigned char md[hashFunctionSize[hash]];
89 funcs[hash](
reinterpret_cast<const unsigned char *
>(stringView.data()),
95 for (
size_t i = 0; i < hashFunctionSize[hash]; ++i) {
96 ss << std::hex << std::setw(2)
97 << std::setfill(
'0') << (int) md[i];
hash utils namespace
Definition: HashUtils.h:19
hash_function
Definition: HashUtils.h:28
@ SHA_384
Definition: HashUtils.h:32
@ SHA_512
Definition: HashUtils.h:33
@ SHA_256
Definition: HashUtils.h:30
@ MD_4
Definition: HashUtils.h:34
@ MD_5
Definition: HashUtils.h:31
@ SHA_224
Definition: HashUtils.h:29
constexpr std::array< unsigned char *(*)(const unsigned char *d, size_t n, unsigned char *md), 6 > funcs
Definition: HashUtils.h:22
std::string getHashStr(std::string_view stringView)
Definition: HashUtils.h:87
std::string hexToString(std::string_view in)
Definition: HashUtils.cpp:15
std::string stringToHex(std::string_view in)
Definition: HashUtils.cpp:4