diff --git a/src/security/generate_uuid.hpp b/src/security/generate_uuid.hpp index 1204d0a..50c90fd 100644 --- a/src/security/generate_uuid.hpp +++ b/src/security/generate_uuid.hpp @@ -11,11 +11,17 @@ namespace hack::security std::string uuid; uuid_t uuid_obj; uuid_generate_time_safe(uuid_obj); - char uuid_ch[37]; + char uuid_ch[UUID_STR_LEN]; uuid_unparse_lower(uuid_obj, uuid_ch); std::stringstream ss; ss << uuid_ch; ss >> uuid; return uuid; } + + inline bool validate_uuid(const std::string& s) + { + static const std::regex e("^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$", std::regex_constants::icase); + return std::regex_match(s, e); + } }