aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-10-11 23:14:48 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-10-11 23:14:48 -0400
commit7f9dc4ebc10eb13e73466224f28ba62747693df9 (patch)
treec9710ef079787b0ebd460006a8f2dce03644d66b /std
parentb61a6ec8a6ba7222efd3749a9c5ae30db7e4ef6b (diff)
downloadzig-7f9dc4ebc10eb13e73466224f28ba62747693df9.tar.gz
zig-7f9dc4ebc10eb13e73466224f28ba62747693df9.zip
fix std.os.getRandomBytes for windows
Diffstat (limited to 'std')
-rw-r--r--std/os/index.zig7
-rw-r--r--std/os/windows/index.zig15
2 files changed, 14 insertions, 8 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 73bcfb2dd6..9ecfb5901c 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -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.
diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig
index 915743843b..90a2a30caa 100644
--- a/std/os/windows/index.zig
+++ b/std/os/windows/index.zig
@@ -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;