[PATCH 2/2] crypt32/tests: Add tests for CryptHashCertificate2

Isira Seneviratne isirasen96 at gmail.com
Wed Jan 23 02:56:06 CST 2019


On Wed, Jan 23, 2019 at 1:26 PM Orhan 'aib' Kavrakoğlu <aibok42 at gmail.com>
wrote:

> ---
>
You need to sign off this patch as well.

>  dlls/crypt32/tests/cert.c | 65 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
>
> diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
> index f653741ea7..ddda156cc5 100644
> --- a/dlls/crypt32/tests/cert.c
> +++ b/dlls/crypt32/tests/cert.c
> @@ -1784,6 +1784,70 @@ static void testCryptHashCert(void)
>      ok(!memcmp(hash, knownHash, sizeof(knownHash)), "Unexpected hash\n");
>  }
>
> +static void testCryptHashCert2(void)
> +{
> +    static const BYTE emptyHash[] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b,
> 0x4b,
> +     0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8,
> 0x07,
> +     0x09 };
> +    static const BYTE knownHash[] = { 0xae, 0x9d, 0xbf, 0x6d, 0xf5, 0x46,
> 0xee,
> +     0x8b, 0xc5, 0x7a, 0x13, 0xba, 0xc2, 0xb1, 0x04, 0xf2, 0xbf, 0x52,
> 0xa8,
> +     0xa2 };
> +    static const BYTE toHash[] =
> "abcdefghijklmnopqrstuvwxyz0123456789.,;!?:";
> +    BOOL ret;
> +    BYTE hash[20];
> +    DWORD hashLen;
> +    const WCHAR SHA1[] = { 'S', 'H', 'A', '1', '\0' };
> +    const WCHAR invalidAlgorithm[] = { 'I', 'H', 'A', '9', '9', '\0' };
> +
> +    /* Test empty hash */
> +    hashLen = sizeof(hash);
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, NULL, 0, hash, &hashLen);
> +    ok(ret, "CryptHashCertificate2 failed: %08x\n", GetLastError());
> +    ok(hashLen == sizeof(hash), "Got unexpected size of hash %d\n",
> hashLen);
> +    ok(!memcmp(hash, emptyHash, sizeof(emptyHash)), "Unexpected hash of
> nothing\n");
> +
> +    /* Test known hash */
> +    hashLen = sizeof(hash);
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, toHash, sizeof(toHash),
> hash, &hashLen);
> +    ok(ret, "CryptHashCertificate2 failed: %08x\n", GetLastError());
> +    ok(hashLen == sizeof(hash), "Got unexpected size of hash %d\n",
> hashLen);
> +    ok(!memcmp(hash, knownHash, sizeof(knownHash)), "Unexpected hash\n");
> +
> +    /* Test null hash size pointer just sets hash size */
> +    hashLen = 0;
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, toHash, sizeof(toHash),
> NULL, &hashLen);
> +    ok(ret, "CryptHashCertificate2 failed: %08x\n", GetLastError());
> +    ok(hashLen == sizeof(hash), "Hash size not set correctly (%d)\n",
> hashLen);
> +
> +    /* Test invalid algorithm ID */
> +    hashLen = sizeof(hash);
> +    ret = CryptHashCertificate2(NULL, 0, NULL, toHash, sizeof(toHash),
> hash, &hashLen);
> +    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
> +     "Expected ERROR_INVALID_PARAMETER (%d), got %d\n",
> ERROR_INVALID_PARAMETER, GetLastError());
> +
> +    /* Test invalid algorithm */
> +    hashLen = sizeof(hash);
> +    ret = CryptHashCertificate2(invalidAlgorithm, 0, NULL, toHash,
> sizeof(toHash), hash, &hashLen);
> +    ok(!ret && GetLastError() == ERROR_INVALID_FUNCTION,
> +     "Expected ERROR_INVALID_FUNCTION (%d), got %d\n",
> ERROR_INVALID_FUNCTION, GetLastError());
> +
> +    /* Test hash buffer too small */
> +    hashLen = sizeof(hash) / 2;
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, toHash, sizeof(toHash),
> hash, &hashLen);
> +    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
> +     "Expected ERROR_INVALID_PARAMETER (%d), got %d\n",
> ERROR_INVALID_PARAMETER, GetLastError());
> +
> +    /* Test hashLen null with hash */
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, toHash, sizeof(toHash),
> hash, NULL);
> +    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
> +     "Expected ERROR_INVALID_PARAMETER (%d), got %d\n",
> ERROR_INVALID_PARAMETER, GetLastError());
> +
> +    /* Test hashLen null with no hash */
> +    ret = CryptHashCertificate2(SHA1, 0, NULL, toHash, sizeof(toHash),
> NULL, NULL);
> +    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
> +     "Expected ERROR_INVALID_PARAMETER (%d), got %d\n",
> ERROR_INVALID_PARAMETER, GetLastError());
> +}
> +
>  static void verifySig(HCRYPTPROV csp, const BYTE *toSign, size_t
> toSignLen,
>   const BYTE *sig, unsigned int sigLen)
>  {
> @@ -4074,6 +4138,7 @@ START_TEST(cert)
>      testLinkCert();
>
>      testCryptHashCert();
> +    testCryptHashCert2();
>      testCertSigs();
>      testSignAndEncodeCert();
>      testCreateSelfSignCert();
> --
> 2.19.1
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20190123/38061fd5/attachment.html>


More information about the wine-devel mailing list