[PATCH 2/3] advapi32: Use helper for converting crypt objects handles to pointers.
Alexandre Julliard
julliard at winehq.org
Wed Feb 17 09:24:37 CST 2021
Paul Gofman <pgofman at 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.
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list