Paul Gofman pgofman@codeweavers.com writes:
@@ -57,6 +57,37 @@ static HWND crypt_hWindow; #define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size)) #define CRYPT_Free(buffer) (LocalFree(buffer))
+static void *pointer_from_handle(UINT_PTR handle, DWORD magic, DWORD invalid_handle_error_code) +{
- if (!handle)
- {
SetLastError(invalid_handle_error_code);
return NULL;
- }
- if (*(DWORD *)handle != magic)
- {
SetLastError(ERROR_INVALID_PARAMETER);
return NULL;
- }
- return (void *)handle;
+}
+static PCRYPTPROV provider_from_handle(HCRYPTPROV handle, DWORD invalid_handle_error_code) +{
- return pointer_from_handle(handle, MAGIC_CRYPTPROV, invalid_handle_error_code);
+}
+static PCRYPTHASH hash_from_handle(HCRYPTHASH handle, DWORD invalid_handle_error_code) +{
- return pointer_from_handle(handle, MAGIC_CRYPTHASH, invalid_handle_error_code);
+}
+static PCRYPTKEY key_from_handle(HCRYPTKEY handle, DWORD invalid_handle_error_code) +{
- return pointer_from_handle(handle, MAGIC_CRYPTKEY, invalid_handle_error_code);
+}
That's not very nice. I'd suggest to always fail with ERROR_INVALID_PARAMETER. The few places that really need a different error code can handle it themselves.