From 45b00b6faea567783c5f3e0a74b48cb98d34ef53 Mon Sep 17 00:00:00 2001 From: chatlanin Date: Thu, 10 Nov 2022 11:16:43 +0300 Subject: [PATCH] add validate uuid --- src/security/generate_uuid.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); + } }