diff --git a/services/lib/src/GlobalTools.h b/services/lib/src/GlobalTools.h --- a/services/lib/src/GlobalTools.h +++ b/services/lib/src/GlobalTools.h @@ -19,6 +19,8 @@ std::string generateUUID(); +bool validateUUIDv4(const std::string &uuid); + } // namespace tools } // namespace network } // namespace comm diff --git a/services/lib/src/GlobalTools.cpp b/services/lib/src/GlobalTools.cpp --- a/services/lib/src/GlobalTools.cpp +++ b/services/lib/src/GlobalTools.cpp @@ -1,5 +1,6 @@ #include "GlobalTools.h" +#include #include #include #include @@ -7,6 +8,7 @@ #include #include +#include #include namespace comm { @@ -43,6 +45,18 @@ return boost::uuids::to_string(random_generator()); } +bool validateUUIDv4(const std::string &uuid) { + const std::regex uuidV4RegexFormat( + "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"); + try { + return std::regex_match(uuid, uuidV4RegexFormat); + } catch (const std::exception &e) { + LOG(ERROR) << "Tools: " + << "Got an exception at `validateUUID`: " << e.what(); + return false; + } +} + } // namespace tools } // namespace network } // namespace comm