From 82a6fba6ec0c5a667582b9ad48adadc36bef2702 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 28 Apr 2024 18:17:48 +0100 Subject: [PATCH] tokenmgr: separate getRandomUUID from registerNewToken --- src/managers/TokenManager.cpp | 8 +++++++- src/managers/TokenManager.hpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/managers/TokenManager.cpp b/src/managers/TokenManager.cpp index 8f7929ee..89db3256 100644 --- a/src/managers/TokenManager.cpp +++ b/src/managers/TokenManager.cpp @@ -10,7 +10,7 @@ std::string CUUIDToken::getUUID() { return uuid; } -std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_clock::duration expires) { +std::string CTokenManager::getRandomUUID() { std::string uuid; do { uuid_t uuid_; @@ -20,6 +20,12 @@ std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_c (uint16_t)uuid_[9], (uint16_t)uuid_[10], (uint16_t)uuid_[11], (uint16_t)uuid_[12], (uint16_t)uuid_[13], (uint16_t)uuid_[14], (uint16_t)uuid_[15]); } while (m_mTokens.contains(uuid)); + return uuid; +} + +std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_clock::duration expires) { + std::string uuid = getRandomUUID(); + m_mTokens[uuid] = std::make_shared(uuid, data, expires); return uuid; } diff --git a/src/managers/TokenManager.hpp b/src/managers/TokenManager.hpp index 45b0679a..ead02275 100644 --- a/src/managers/TokenManager.hpp +++ b/src/managers/TokenManager.hpp @@ -25,6 +25,7 @@ class CUUIDToken { class CTokenManager { public: std::string registerNewToken(std::any data, std::chrono::system_clock::duration expires); + std::string getRandomUUID(); std::shared_ptr getToken(const std::string& uuid); void removeToken(std::shared_ptr token);