From 7b1ed4bd956a7db7bdc49972e24f3554367c857a Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 6 Aug 2025 17:54:24 +0300 Subject: [PATCH] Make util::make_uuid use md5 hash --- libs/util/include/psemek/util/uuid.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libs/util/include/psemek/util/uuid.hpp b/libs/util/include/psemek/util/uuid.hpp index 9170f956..3987444f 100644 --- a/libs/util/include/psemek/util/uuid.hpp +++ b/libs/util/include/psemek/util/uuid.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -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(c); - } - }; + auto md5_result = md5_inl::hash(str); + + uuid result; + result.values[0] = static_cast(md5_result[0]) | (static_cast(md5_result[1]) << 32); + result.values[1] = static_cast(md5_result[2]) | (static_cast(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; }