authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-11 23:14:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-11 23:14:48-04:00
log7f9dc4ebc10eb13e73466224f28ba62747693df9
treec9710ef079787b0ebd460006a8f2dce03644d66b
parentb61a6ec8a6ba7222efd3749a9c5ae30db7e4ef6b

fix std.os.getRandomBytes for windows


2 files changed, 14 insertions(+), 8 deletions(-)

std/os/index.zig+6-1
...@@ -85,7 +85,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -85,7 +85,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
85 },85 },
86 Os.windows => {86 Os.windows => {
87 var hCryptProv: windows.HCRYPTPROV = undefined;87 var hCryptProv: windows.HCRYPTPROV = undefined;
88 if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {88 if (!windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
89 return error.Unexpected;89 return error.Unexpected;
90 }90 }
91 defer _ = windows.CryptReleaseContext(hCryptProv, 0);91 defer _ = windows.CryptReleaseContext(hCryptProv, 0);
...@@ -98,6 +98,11 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -98,6 +98,11 @@ pub fn getRandomBytes(buf: []u8) -> %void {
98 }98 }
99}99}
100100
101test "os.getRandomBytes" {
102 var buf: [50]u8 = undefined;
103 %%getRandomBytes(buf[0..]);
104}
105
101/// Raises a signal in the current kernel thread, ending its execution.106/// Raises a signal in the current kernel thread, ending its execution.
102/// If linking against libc, this calls the abort() libc function. Otherwise107/// If linking against libc, this calls the abort() libc function. Otherwise
103/// it uses the zig standard library implementation.108/// it uses the zig standard library implementation.
std/os/windows/index.zig+8-7
...@@ -1,18 +1,19 @@...@@ -1,18 +1,19 @@
1pub const ERROR = @import("error.zig");1pub const ERROR = @import("error.zig");
22
3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,
4 pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
5
6pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
7
8pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
9
10
3pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;11pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
412
5pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,13pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: DWORD,
6 dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,14 dwShareMode: DWORD, lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, dwCreationDisposition: DWORD,
7 dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;15 dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE;
816
9pub extern "kernel32" stdcallcc fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR,
10 pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
11
12pub extern "kernel32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
13
14pub extern "kernel32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
15
16pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;17pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;
1718
18pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;19pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;