add validate uuid

This commit is contained in:
chatlanin 2022-11-10 11:16:43 +03:00
parent 794658e57c
commit 45b00b6fae

View File

@ -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);
}
}