#include <array>
#include <chrono>
#include <cstdint>
#include <random>
#include <string>
#include "uuid.hpp"
namespace ddwaf {
namespace {
using clock = std::chrono::system_clock;
auto init_rng()
{
return std::mt19937_64{static_cast<uint64_t>(clock::now().time_since_epoch().count())};
}
}
std::string uuidv4_generate_pseudo()
{
static thread_local auto rng = init_rng();
union {
uint8_t byte[16];
uint64_t qword[2];
} uuid_bytes{};
uuid_bytes.qword[0] = rng();
uuid_bytes.qword[1] = rng();
uuid_bytes.byte[6] = 0x4F & (0x40 | uuid_bytes.byte[4]);
uuid_bytes.byte[8] = 0x1b;
std::string result;
result.resize(36);
char *buffer = result.data();
static constexpr auto hex_chars = std::array<char, 17>{"0123456789abcdef"};
for (int i = 0, j = 0; i < 16; ++i) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
buffer[j++] = '-';
}
buffer[j++] = hex_chars[(uuid_bytes.byte[i] >> 4) & 0x0F];
buffer[j++] = hex_chars[uuid_bytes.byte[i] & 0x0F];
}
return result;
}
}