mshtml: Added IHTMLCommentElement stub implementation.
[wine.git] / dlls / crypt32 / tests / oid.c
blobe2e8bc4d1b75a5e1d7a644efe98da2ae92e58c23
1 /*
2 * Unit test suite for crypt32.dll's OID support functions.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winerror.h>
25 #include <wincrypt.h>
26 #include <winreg.h>
28 #include "wine/test.h"
31 static BOOL (WINAPI *pCryptEnumOIDInfo)(DWORD,DWORD,void*,PFN_CRYPT_ENUM_OID_INFO);
34 struct OIDToAlgID
36 LPCSTR oid;
37 DWORD algID;
40 static const struct OIDToAlgID oidToAlgID[] = {
41 { szOID_RSA_RSA, CALG_RSA_KEYX },
42 { szOID_RSA_MD2RSA, CALG_MD2 },
43 { szOID_RSA_MD4RSA, CALG_MD4 },
44 { szOID_RSA_MD5RSA, CALG_MD5 },
45 { szOID_RSA_SHA1RSA, CALG_SHA },
46 { szOID_RSA_DH, CALG_DH_SF },
47 { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
48 { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES },
49 { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 },
50 { szOID_RSA_MD2, CALG_MD2 },
51 { szOID_RSA_MD4, CALG_MD4 },
52 { szOID_RSA_MD5, CALG_MD5 },
53 { szOID_RSA_RC2CBC, CALG_RC2 },
54 { szOID_RSA_RC4, CALG_RC4 },
55 { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
56 { szOID_ANSI_X942_DH, CALG_DH_SF },
57 { szOID_X957_DSA, CALG_DSS_SIGN },
58 { szOID_X957_SHA1DSA, CALG_SHA },
59 { szOID_OIWSEC_md4RSA, CALG_MD4 },
60 { szOID_OIWSEC_md5RSA, CALG_MD5 },
61 { szOID_OIWSEC_md4RSA2, CALG_MD4 },
62 { szOID_OIWSEC_desCBC, CALG_DES },
63 { szOID_OIWSEC_dsa, CALG_DSS_SIGN },
64 { szOID_OIWSEC_shaDSA, CALG_SHA },
65 { szOID_OIWSEC_shaRSA, CALG_SHA },
66 { szOID_OIWSEC_sha, CALG_SHA },
67 { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX },
68 { szOID_OIWSEC_sha1, CALG_SHA },
69 { szOID_OIWSEC_dsaSHA1, CALG_SHA },
70 { szOID_OIWSEC_sha1RSASign, CALG_SHA },
71 { szOID_OIWDIR_md2RSA, CALG_MD2 },
72 { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA },
73 { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN },
76 static const struct OIDToAlgID algIDToOID[] = {
77 { szOID_RSA_RSA, CALG_RSA_KEYX },
78 { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM },
79 { szOID_RSA_MD2, CALG_MD2 },
80 { szOID_RSA_MD4, CALG_MD4 },
81 { szOID_RSA_MD5, CALG_MD5 },
82 { szOID_RSA_RC2CBC, CALG_RC2 },
83 { szOID_RSA_RC4, CALG_RC4 },
84 { szOID_RSA_DES_EDE3_CBC, CALG_3DES },
85 { szOID_ANSI_X942_DH, CALG_DH_SF },
86 { szOID_X957_DSA, CALG_DSS_SIGN },
87 { szOID_OIWSEC_desCBC, CALG_DES },
88 { szOID_OIWSEC_sha1, CALG_SHA },
91 static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
92 static const WCHAR bogus2Dll[] = { 'b','o','g','u','s','2','.','d','l','l',0 };
94 static void testOIDToAlgID(void)
96 int i;
97 DWORD alg;
99 /* Test with a bogus one */
100 SetLastError(0xdeadbeef);
101 alg = CertOIDToAlgId("1.2.3");
102 ok(!alg, "Expected failure, got %d\n", alg);
103 ok(GetLastError() == 0xdeadbeef ||
104 GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND ||
105 GetLastError() == ERROR_SUCCESS, /* win2k */
106 "Expected ERROR_RESOURCE_NAME_NOT_FOUND, ERROR_SUCCESS "
107 "or no error set, got %08x\n", GetLastError());
109 for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
111 alg = CertOIDToAlgId(oidToAlgID[i].oid);
112 /* Not all Windows installations support all these, so make sure it's
113 * at least not the wrong one.
115 ok(alg == 0 || alg == oidToAlgID[i].algID,
116 "Expected %d, got %d\n", oidToAlgID[i].algID, alg);
120 static void testAlgIDToOID(void)
122 int i;
123 LPCSTR oid;
125 /* Test with a bogus one */
126 SetLastError(0xdeadbeef);
127 oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
128 ok(!oid && GetLastError() == 0xdeadbeef,
129 "Didn't expect last error (%08x) to be set\n", GetLastError());
130 for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
132 oid = CertAlgIdToOID(algIDToOID[i].algID);
133 /* Allow failure, not every version of Windows supports every algo */
134 if (oid)
135 ok(!strcmp(oid, algIDToOID[i].oid),
136 "Expected %s, got %s\n", algIDToOID[i].oid, oid);
140 static void test_oidFunctionSet(void)
142 HCRYPTOIDFUNCSET set1, set2;
143 BOOL ret;
144 LPWSTR buf = NULL;
145 DWORD size;
147 /* This crashes
148 set = CryptInitOIDFunctionSet(NULL, 0);
151 /* The name doesn't mean much */
152 set1 = CryptInitOIDFunctionSet("funky", 0);
153 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
154 if (set1)
156 /* These crash
157 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
158 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
160 size = 0;
161 ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
162 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
163 if (ret)
165 buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
166 if (buf)
168 ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
169 ok(ret, "CryptGetDefaultOIDDllList failed: %08x\n",
170 GetLastError());
171 ok(!*buf, "Expected empty DLL list\n");
172 HeapFree(GetProcessHeap(), 0, buf);
177 /* MSDN says flags must be 0, but it's not checked */
178 set1 = CryptInitOIDFunctionSet("", 1);
179 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
180 set2 = CryptInitOIDFunctionSet("", 0);
181 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
182 /* There isn't a free function, so there must be only one set per name to
183 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
185 ok(set1 == set2, "Expected identical sets\n");
186 if (set1)
188 /* The empty name function set used here seems to correspond to
189 * DEFAULT.
193 /* There's no installed function for a built-in encoding. */
194 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
195 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
196 if (set1)
198 void *funcAddr;
199 HCRYPTOIDFUNCADDR hFuncAddr;
201 ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
202 &funcAddr, &hFuncAddr);
203 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
204 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
208 typedef int (*funcY)(int);
210 static int funky(int x)
212 return x;
215 static void test_installOIDFunctionAddress(void)
217 BOOL ret;
218 CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
219 HCRYPTOIDFUNCSET set;
221 /* This crashes
222 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
225 /* Installing zero functions should work */
226 SetLastError(0xdeadbeef);
227 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
228 NULL, 0);
229 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
230 GetLastError());
232 /* The function name doesn't much matter */
233 SetLastError(0xdeadbeef);
234 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
235 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
236 GetLastError());
237 SetLastError(0xdeadbeef);
238 entry.pszOID = X509_CERT;
239 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
240 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
241 GetLastError());
242 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
243 ok(set != 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
244 if (set)
246 funcY funcAddr = NULL;
247 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
249 /* This crashes
250 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
251 NULL);
253 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
254 (void **)&funcAddr, &hFuncAddr);
255 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
256 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
257 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
258 (void **)&funcAddr, &hFuncAddr);
259 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
260 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
261 ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
262 (void **)&funcAddr, &hFuncAddr);
263 ok(ret, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
264 if (funcAddr)
266 int y = funcAddr(0xabadc0da);
268 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
269 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
274 static void test_registerOIDFunction(void)
276 BOOL ret;
278 /* oddly, this succeeds under WinXP; the function name key is merely
279 * omitted. This may be a side effect of the registry code, I don't know.
280 * I don't check it because I doubt anyone would depend on it.
281 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
282 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
284 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
285 * E_INVALIDARG
287 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, bogusDll,
288 NULL);
289 ok(!ret && GetLastError() == E_INVALIDARG,
290 "Expected E_INVALIDARG: %d\n", GetLastError());
291 /* This has no effect, but "succeeds" on XP */
292 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
293 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
294 ok(ret, "Expected pseudo-success, got %d\n", GetLastError());
295 SetLastError(0xdeadbeef);
296 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
297 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
298 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
300 skip("Need admin rights\n");
301 return;
303 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
304 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
305 "1.2.3.4.5.6.7.8.9.10");
306 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
307 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
308 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
309 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
310 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
311 "1.2.3.4.5.6.7.8.9.10");
312 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
313 /* This has no effect */
314 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
315 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
316 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
317 /* Check with bogus encoding type: */
318 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
319 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
320 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
321 /* This is written with value 3 verbatim. Thus, the encoding type isn't
322 * (for now) treated as a mask.
324 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
325 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
326 ok(ret, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
327 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
328 "1.2.3.4.5.6.7.8.9.10");
329 ok(ret, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
332 static void test_registerDefaultOIDFunction(void)
334 static const char fmt[] =
335 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
336 static const char func[] = "CertDllOpenStoreProv";
337 char buf[MAX_PATH];
338 BOOL ret;
339 long rc;
340 HKEY key;
342 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, NULL);
343 ok(!ret && GetLastError() == E_INVALIDARG,
344 "Expected E_INVALIDARG, got %08x\n", GetLastError());
345 /* This succeeds on WinXP, although the bogus entry is unusable.
346 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
348 /* Register one at index 0 */
349 SetLastError(0xdeadbeef);
350 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
351 bogusDll);
352 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
354 skip("Need admin rights\n");
355 return;
357 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
358 /* Reregistering should fail */
359 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
360 bogusDll);
361 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
362 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
363 /* Registering the same one at index 1 should also fail */
364 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
365 bogusDll);
366 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
367 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
368 /* Registering a different one at index 1 succeeds */
369 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
370 bogus2Dll);
371 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
372 sprintf(buf, fmt, 0, func);
373 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, buf, &key);
374 ok(rc == 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc);
375 if (rc == 0)
377 static const CHAR dllA[] = "Dll";
378 static const CHAR bogusDll_A[] = "bogus.dll";
379 static const CHAR bogus2Dll_A[] = "bogus2.dll";
380 CHAR dllBuf[MAX_PATH];
381 DWORD type, size;
382 LPSTR ptr;
384 size = sizeof(dllBuf) / sizeof(dllBuf[0]);
385 rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
386 ok(rc == 0,
387 "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc);
388 ok(type == REG_MULTI_SZ, "Expected type REG_MULTI_SZ, got %d\n", type);
389 /* bogusDll was registered first, so that should be first */
390 ptr = dllBuf;
391 ok(!lstrcmpiA(ptr, bogusDll_A), "Unexpected dll\n");
392 ptr += lstrlenA(ptr) + 1;
393 ok(!lstrcmpiA(ptr, bogus2Dll_A), "Unexpected dll\n");
394 RegCloseKey(key);
396 /* Unregister both of them */
397 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
398 bogusDll);
399 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
400 GetLastError());
401 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
402 bogus2Dll);
403 ok(ret, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
404 GetLastError());
405 /* Now that they're both unregistered, unregistering should fail */
406 ret = CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
407 bogusDll);
408 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
409 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
411 /* Repeat a few tests on the normal encoding type */
412 ret = CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING,
413 "CertDllOpenStoreProv", 0, bogusDll);
414 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
415 "CertDllOpenStoreProv", bogusDll);
416 ok(ret, "CryptUnregisterDefaultOIDFunction failed\n");
417 ret = CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING,
418 "CertDllOpenStoreProv", bogusDll);
419 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
420 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
423 static void test_getDefaultOIDFunctionAddress(void)
425 BOOL ret;
426 HCRYPTOIDFUNCSET set;
427 void *funcAddr;
428 HCRYPTOIDFUNCADDR hFuncAddr;
430 /* Crash
431 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
432 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
433 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
434 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
435 &hFuncAddr);
437 set = CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
438 ok(set != 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
439 /* This crashes if hFuncAddr is not 0 to begin with */
440 hFuncAddr = 0;
441 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
442 &hFuncAddr);
443 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
444 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
445 /* This fails with the normal encoding too, so built-in functions aren't
446 * returned.
448 ret = CryptGetDefaultOIDFunctionAddress(set, X509_ASN_ENCODING, NULL, 0,
449 &funcAddr, &hFuncAddr);
450 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
451 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
453 /* Even with a registered dll, this fails (since the dll doesn't exist) */
454 SetLastError(0xdeadbeef);
455 ret = CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
456 bogusDll);
457 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
458 skip("Need admin rights\n");
459 else
460 ok(ret, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
461 ret = CryptGetDefaultOIDFunctionAddress(set, 0, NULL, 0, &funcAddr,
462 &hFuncAddr);
463 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
464 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
465 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll);
468 static BOOL WINAPI countOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
470 (*(DWORD *)pvArg)++;
471 return TRUE;
474 static BOOL WINAPI noOidInfo(PCCRYPT_OID_INFO pInfo, void *pvArg)
476 return FALSE;
479 static void test_enumOIDInfo(void)
481 BOOL ret;
482 DWORD count = 0;
484 if (!pCryptEnumOIDInfo)
486 skip("CryptEnumOIDInfo() is not available\n");
487 return;
490 /* This crashes
491 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
494 /* Silly tests, check that more than one thing is enumerated */
495 ret = pCryptEnumOIDInfo(0, 0, &count, countOidInfo);
496 ok(ret && count > 0, "Expected more than item enumerated\n");
497 ret = pCryptEnumOIDInfo(0, 0, NULL, noOidInfo);
498 ok(!ret, "Expected FALSE\n");
501 static void test_findOIDInfo(void)
503 static WCHAR sha1[] = { 's','h','a','1',0 };
504 static CHAR oid_rsa_md5[] = szOID_RSA_MD5;
505 ALG_ID alg = CALG_SHA1;
506 ALG_ID algs[2] = { CALG_MD5, CALG_RSA_SIGN };
507 PCCRYPT_OID_INFO info;
509 info = CryptFindOIDInfo(0, NULL, 0);
510 ok(info == NULL, "Expected NULL\n");
511 info = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, oid_rsa_md5, 0);
512 ok(info != NULL, "Expected to find szOID_RSA_MD5\n");
513 if (info)
515 ok(!strcmp(info->pszOID, szOID_RSA_MD5), "Expected %s, got %s\n",
516 szOID_RSA_MD5, info->pszOID);
517 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
518 U(*info).Algid);
520 info = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, sha1, 0);
521 ok(info != NULL, "Expected to find sha1\n");
522 if (info)
524 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
525 szOID_OIWSEC_sha1, info->pszOID);
526 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
527 U(*info).Algid);
529 info = CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY, &alg, 0);
530 ok(info != NULL, "Expected to find sha1\n");
531 if (info)
533 ok(!strcmp(info->pszOID, szOID_OIWSEC_sha1), "Expected %s, got %s\n",
534 szOID_OIWSEC_sha1, info->pszOID);
535 ok(U(*info).Algid == CALG_SHA1, "Expected CALG_SHA1, got %d\n",
536 U(*info).Algid);
538 info = CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY, algs, 0);
539 ok(info != NULL, "Expected to find md5RSA\n");
540 if (info)
542 ok(!strcmp(info->pszOID, szOID_RSA_MD5RSA), "Expected %s, got %s\n",
543 szOID_RSA_MD5RSA, info->pszOID);
544 ok(U(*info).Algid == CALG_MD5, "Expected CALG_MD5, got %d\n",
545 U(*info).Algid);
549 START_TEST(oid)
551 HMODULE hCrypt32 = GetModuleHandleA("crypt32.dll");
552 pCryptEnumOIDInfo = (void*)GetProcAddress(hCrypt32, "CryptEnumOIDInfo");
554 testOIDToAlgID();
555 testAlgIDToOID();
556 test_enumOIDInfo();
557 test_findOIDInfo();
558 test_oidFunctionSet();
559 test_installOIDFunctionAddress();
560 test_registerOIDFunction();
561 test_registerDefaultOIDFunction();
562 test_getDefaultOIDFunctionAddress();