From 6be643fd1cc2c417243c274d771941b29c9c4676 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Sun, 6 Aug 2023 12:40:01 +0200 Subject: [PATCH] urandom: fix for Nim 2.0 by using only CryptAcquireContextW Before this commit, compiling urandom.nim on Windows with Nim 2.0 would produce an error: $ nim c --os:windows uuids/urandom.nim /foo/pragmagic-uuids/uuids/urandom.nim(15, 8) Error: undeclared identifier: 'useWinUnicode' This was because Nim 2.0 [1] removed the useWinUnicode identifier [2]. Fix by always using CryptAcquireContextW on Windows. Fixes: #8 [1] https://nim-lang.org/blog/2023/08/01/nim-v20-released.html [2] https://github.com/nim-lang/Nim/commit/612abda4f40b2a0fd8dd0e4ad119c4415b9c34cb --- uuids/urandom.nim | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/uuids/urandom.nim b/uuids/urandom.nim index 6078de4..b0cb0b5 100644 --- a/uuids/urandom.nim +++ b/uuids/urandom.nim @@ -12,16 +12,10 @@ when defined(windows): {.push, stdcall, dynlib: "Advapi32.dll".} - when useWinUnicode: - proc CryptAcquireContext( - phProv: ptr HCRYPTPROV, pszContainer: WideCString, - pszProvider: WideCString, dwProvType: DWORD, dwFlags: DWORD - ): WINBOOL {.importc: "CryptAcquireContextW".} - else: - proc CryptAcquireContext( - phProv: ptr HCRYPTPROV, pszContainer: cstring, pszProvider: cstring, - dwProvType: DWORD, dwFlags: DWORD - ): WINBOOL {.importc: "CryptAcquireContextA".} + proc CryptAcquireContext( + phProv: ptr HCRYPTPROV, pszContainer: WideCString, + pszProvider: WideCString, dwProvType: DWORD, dwFlags: DWORD + ): WINBOOL {.importc: "CryptAcquireContextW".} proc CryptGenRandom( hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: pointer