Make util::make_uuid use md5 hash
This commit is contained in:
parent
e57b284ffc
commit
7b1ed4bd95
1 changed files with 7 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/util/hash.hpp>
|
#include <psemek/util/hash.hpp>
|
||||||
|
#include <psemek/util/md5_inl.hpp>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
@ -46,18 +47,14 @@ namespace psemek::util
|
||||||
// TODO: use SHA-1 or something like that?
|
// TODO: use SHA-1 or something like that?
|
||||||
constexpr uuid make_uuid(std::string_view str)
|
constexpr uuid make_uuid(std::string_view str)
|
||||||
{
|
{
|
||||||
struct char_hash
|
auto md5_result = md5_inl::hash(str);
|
||||||
{
|
|
||||||
constexpr std::size_t operator()(char c) const noexcept
|
uuid result;
|
||||||
{
|
result.values[0] = static_cast<std::uint64_t>(md5_result[0]) | (static_cast<std::uint64_t>(md5_result[1]) << 32);
|
||||||
return static_cast<std::size_t>(c);
|
result.values[1] = static_cast<std::uint64_t>(md5_result[2]) | (static_cast<std::uint64_t>(md5_result[3]) << 32);
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
uuid result{0x6eb49abceae6db24ull, 0x476c4c69fd7925a7ull};
|
|
||||||
hash_sequence(result[0], str.begin(), str.end(), char_hash{});
|
|
||||||
hash_sequence(result[1], str.begin(), str.end(), char_hash{});
|
|
||||||
make_rfc_4122(result);
|
make_rfc_4122(result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue