This commit is contained in:
Aron Podrigal 2025-01-15 16:19:14 -06:00
parent fef78d728f
commit 338186ee5e
2 changed files with 15 additions and 10 deletions

View File

@ -1149,7 +1149,7 @@ SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
#endif
}
SWITCH_DECLARE(void) switch_uuid_generate_v4(switch_uuid_t *uuid)
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_v4(switch_uuid_t *uuid)
{
switch_mutex_lock(runtime.uuid_mutex);
#ifndef WIN32

View File

@ -4873,13 +4873,8 @@ SWITCH_DECLARE(int) switch_rand(void)
}
SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
static SWITCH_DECLARE(int) _switch_getentropy(void *buffer, switch_size_t length)
{
if (!buffer || length > 256) { // Enforce same limit as `getentropy`
errno = EIO; // Input/Output error
return -1;
}
#ifdef WIN32
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RNG_ALGORITHM, NULL, 0);
@ -4940,17 +4935,27 @@ SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
}
SWITCH_DECLARE(int) switch_getentropy(void *buffer, switch_size_t length)
{
if (!buffer || length > 256) { // Enforce same limit as `getentropy`
errno = EIO; // Input/Output error
return -1;
}
return _switch_getentropy(buffer, length);
}
SWITCH_DECLARE(switch_status_t) switch_uuid_generate_v7(switch_uuid_t *uuid) {
/* random bytes */
unsigned char *value = uuid->data;
/* current timestamp in ms */
switch_time_t timestamp = switch_time_now() / 1000;
if (switch_getentropy(value, 16) != 0) {
return -1;
}
/* current timestamp in ms */
switch_time_t timestamp = switch_time_now() / 1000;
// timestamp
value[0] = (timestamp >> 40) & 0xFF;
value[1] = (timestamp >> 32) & 0xFF;