add validate uuid
This commit is contained in:
parent
794658e57c
commit
45b00b6fae
@ -11,11 +11,17 @@ namespace hack::security
|
|||||||
std::string uuid;
|
std::string uuid;
|
||||||
uuid_t uuid_obj;
|
uuid_t uuid_obj;
|
||||||
uuid_generate_time_safe(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);
|
uuid_unparse_lower(uuid_obj, uuid_ch);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << uuid_ch;
|
ss << uuid_ch;
|
||||||
ss >> uuid;
|
ss >> uuid;
|
||||||
return 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user