Skip to content

Commit 11b7f58

Browse files
committed
Fix windows errros
1 parent ce7530a commit 11b7f58

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

include/CXXGraph/Utility/SecureRandom.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#if defined(_WIN32) || defined(_WIN64)
77
#include <windows.h>
88
#include <bcrypt.h>
9+
#ifndef STATUS_SUCCESS
10+
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
11+
#endif
912
#pragma comment(lib, "bcrypt.lib")
1013
#else
1114
#include <fstream>
@@ -19,6 +22,8 @@ inline void generateBytes(unsigned char* buffer, size_t length) {
1922
throw std::invalid_argument("Invalid buffer or length");
2023

2124
#if defined(_WIN32) || defined(_WIN64)
25+
if (length > ULONG_MAX)
26+
throw std::length_error("Requested random length too large");
2227
NTSTATUS status = BCryptGenRandom(nullptr, buffer, static_cast<ULONG>(length),
2328
BCRYPT_USE_SYSTEM_PREFERRED_RNG);
2429
if (status != STATUS_SUCCESS)

0 commit comments

Comments
 (0)