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
|
||||
|
||||
#include <psemek/util/hash.hpp>
|
||||
#include <psemek/util/md5_inl.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
|
@ -46,18 +47,14 @@ namespace psemek::util
|
|||
// TODO: use SHA-1 or something like that?
|
||||
constexpr uuid make_uuid(std::string_view str)
|
||||
{
|
||||
struct char_hash
|
||||
{
|
||||
constexpr std::size_t operator()(char c) const noexcept
|
||||
{
|
||||
return static_cast<std::size_t>(c);
|
||||
}
|
||||
};
|
||||
auto md5_result = md5_inl::hash(str);
|
||||
|
||||
uuid result;
|
||||
result.values[0] = static_cast<std::uint64_t>(md5_result[0]) | (static_cast<std::uint64_t>(md5_result[1]) << 32);
|
||||
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);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue