Implemented CryptHashCertificate.
[wine/multimedia.git] / dlls / crypt32 / tests / cert.c
blobc4d8223a7202bba03afbcd21314207597e07dcb2
1 /*
2 * crypt32 cert functions tests
4 * Copyright 2005 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winreg.h>
26 #include <winerror.h>
27 #include <wincrypt.h>
29 #include "wine/test.h"
31 static void testCryptHashCert(void)
33 static const BYTE emptyHash[] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b,
34 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07,
35 0x09 };
36 static const BYTE knownHash[] = { 0xae, 0x9d, 0xbf, 0x6d, 0xf5, 0x46, 0xee,
37 0x8b, 0xc5, 0x7a, 0x13, 0xba, 0xc2, 0xb1, 0x04, 0xf2, 0xbf, 0x52, 0xa8,
38 0xa2 };
39 static const BYTE toHash[] = "abcdefghijklmnopqrstuvwxyz0123456789.,;!?:";
40 BOOL ret;
41 BYTE hash[20];
42 DWORD hashLen = sizeof(hash);
44 /* NULL buffer and nonzero length crashes
45 ret = CryptHashCertificate(0, 0, 0, NULL, size, hash, &hashLen);
46 empty hash length also crashes
47 ret = CryptHashCertificate(0, 0, 0, buf, size, hash, NULL);
49 /* Test empty hash */
50 ret = CryptHashCertificate(0, 0, 0, toHash, sizeof(toHash), NULL,
51 &hashLen);
52 ok(ret, "CryptHashCertificate failed: %08lx\n", GetLastError());
53 ok(hashLen == sizeof(hash),
54 "Got unexpected size of hash %ld, expected %d\n", hashLen, sizeof(hash));
55 /* Test with empty buffer */
56 ret = CryptHashCertificate(0, 0, 0, NULL, 0, hash, &hashLen);
57 ok(ret, "CryptHashCertificate failed: %08lx\n", GetLastError());
58 ok(!memcmp(hash, emptyHash, sizeof(emptyHash)),
59 "Unexpected hash of nothing\n");
60 /* Test a known value */
61 ret = CryptHashCertificate(0, 0, 0, toHash, sizeof(toHash), hash,
62 &hashLen);
63 ok(ret, "CryptHashCertificate failed: %08lx\n", GetLastError());
64 ok(!memcmp(hash, knownHash, sizeof(knownHash)), "Unexpected hash\n");
67 START_TEST(cert)
69 testCryptHashCert();