mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
fix std.os.getRandomBytes for windows
This commit is contained in:
parent
b61a6ec8a6
commit
7f9dc4ebc1
@ -85,7 +85,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
|
||||
},
|
||||
Os.windows => {
|
||||
var hCryptProv: windows.HCRYPTPROV = undefined;
|
||||
if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
|
||||
if (!windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
|
||||
return error.Unexpected;
|
||||
}
|
||||
defer _ = windows.CryptReleaseContext(hCryptProv, 0);
|
||||
@ -98,6 +98,11 @@ pub fn getRandomBytes(buf: []u8) -> %void {
|
||||
}
|
||||
}
|
||||
|
||||
test "os.getRandomBytes" {
|
||||
var buf: [50]u8 = undefined;
|
||||
%%getRandomBytes(buf[0..]);
|
||||
}
|
||||
|
||||
/// Raises a signal in the current kernel thread, ending its execution.
|
||||
/// If linking against libc, this calls the abort() libc function. Otherwise
|
||||
/// it uses the zig standard library implementation.
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
pub const ERROR = @import("error.zig");
|
||||
|
||||
pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,
|
||||
pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
|
||||
|
||||
pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
|
||||
|
||||
pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
|
||||
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
|
||||
dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
|
||||
dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR,
|
||||
pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user