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
28 #include "wine/test.h"
31 static BOOL (WINAPI
*pCryptEnumOIDInfo
)(DWORD
,DWORD
,void*,PFN_CRYPT_ENUM_OID_INFO
);
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)
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_INVALID_PARAMETER
|| /* Vista */
106 GetLastError() == ERROR_SUCCESS
|| /* win2k */
107 GetLastError() == ERROR_FILE_INVALID
, /* another Vista */
108 "Expected ERROR_RESOURCE_NAME_NOT_FOUND, ERROR_INVALID_PARAMETER, "
109 "ERROR_SUCCESS or no error set, got %08x\n", GetLastError());
111 for (i
= 0; i
< sizeof(oidToAlgID
) / sizeof(oidToAlgID
[0]); i
++)
113 alg
= CertOIDToAlgId(oidToAlgID
[i
].oid
);
114 /* Not all Windows installations support all these, so make sure it's
115 * at least not the wrong one.
117 ok(alg
== 0 || alg
== oidToAlgID
[i
].algID
,
118 "Expected %d, got %d\n", oidToAlgID
[i
].algID
, alg
);
122 static void testAlgIDToOID(void)
127 /* Test with a bogus one */
128 SetLastError(0xdeadbeef);
129 oid
= CertAlgIdToOID(ALG_CLASS_SIGNATURE
| ALG_TYPE_ANY
| 80);
130 ok(!oid
&& GetLastError() == 0xdeadbeef,
131 "Didn't expect last error (%08x) to be set\n", GetLastError());
132 for (i
= 0; i
< sizeof(algIDToOID
) / sizeof(algIDToOID
[0]); i
++)
134 oid
= CertAlgIdToOID(algIDToOID
[i
].algID
);
135 /* Allow failure, not every version of Windows supports every algo */
137 ok(!strcmp(oid
, algIDToOID
[i
].oid
),
138 "Expected %s, got %s\n", algIDToOID
[i
].oid
, oid
);
142 static void test_oidFunctionSet(void)
144 HCRYPTOIDFUNCSET set1
, set2
;
150 set = CryptInitOIDFunctionSet(NULL, 0);
153 /* The name doesn't mean much */
154 set1
= CryptInitOIDFunctionSet("funky", 0);
155 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
159 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
160 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
163 ret
= CryptGetDefaultOIDDllList(set1
, 0, NULL
, &size
);
164 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n", GetLastError());
167 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
170 ret
= CryptGetDefaultOIDDllList(set1
, 0, buf
, &size
);
171 ok(ret
, "CryptGetDefaultOIDDllList failed: %08x\n",
173 ok(!*buf
, "Expected empty DLL list\n");
174 HeapFree(GetProcessHeap(), 0, buf
);
179 /* MSDN says flags must be 0, but it's not checked */
180 set1
= CryptInitOIDFunctionSet("", 1);
181 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
182 set2
= CryptInitOIDFunctionSet("", 0);
183 ok(set2
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
184 /* There isn't a free function, so there must be only one set per name to
185 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
187 ok(set1
== set2
, "Expected identical sets\n");
190 /* The empty name function set used here seems to correspond to
195 /* There's no installed function for a built-in encoding. */
196 set1
= CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
197 ok(set1
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
201 HCRYPTOIDFUNCADDR hFuncAddr
;
203 ret
= CryptGetOIDFunctionAddress(set1
, X509_ASN_ENCODING
, X509_CERT
, 0,
204 &funcAddr
, &hFuncAddr
);
205 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
206 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
210 typedef int (*funcY
)(int);
212 static int funky(int x
)
217 static void test_installOIDFunctionAddress(void)
220 CRYPT_OID_FUNC_ENTRY entry
= { CRYPT_DEFAULT_OID
, funky
};
221 HCRYPTOIDFUNCSET set
;
224 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
227 /* Installing zero functions should work */
228 SetLastError(0xdeadbeef);
229 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "CryptDllEncodeObject", 0,
231 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
234 /* The function name doesn't much matter */
235 SetLastError(0xdeadbeef);
236 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 0, NULL
, 0);
237 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
239 SetLastError(0xdeadbeef);
240 entry
.pszOID
= X509_CERT
;
241 ret
= CryptInstallOIDFunctionAddress(NULL
, 0, "OhSoFunky", 1, &entry
, 0);
242 ok(ret
&& GetLastError() == 0xdeadbeef, "Expected success, got %08x\n",
244 set
= CryptInitOIDFunctionSet("OhSoFunky", 0);
245 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %08x\n", GetLastError());
248 funcY funcAddr
= NULL
;
249 HCRYPTOIDFUNCADDR hFuncAddr
= NULL
;
252 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
255 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, 0, 0,
256 (void **)&funcAddr
, &hFuncAddr
);
257 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
258 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
259 ret
= CryptGetOIDFunctionAddress(set
, X509_ASN_ENCODING
, X509_CERT
, 0,
260 (void **)&funcAddr
, &hFuncAddr
);
261 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
262 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
263 ret
= CryptGetOIDFunctionAddress(set
, 0, X509_CERT
, 0,
264 (void **)&funcAddr
, &hFuncAddr
);
265 ok(ret
, "CryptGetOIDFunctionAddress failed: %d\n", GetLastError());
268 int y
= funcAddr(0xabadc0da);
270 ok(y
== 0xabadc0da, "Unexpected return (%d) from function\n", y
);
271 CryptFreeOIDFunctionAddress(hFuncAddr
, 0);
276 static void test_registerOIDFunction(void)
280 /* oddly, this succeeds under WinXP; the function name key is merely
281 * omitted. This may be a side effect of the registry code, I don't know.
282 * I don't check it because I doubt anyone would depend on it.
283 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
284 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
286 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
289 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo", NULL
, bogusDll
,
291 ok(!ret
&& GetLastError() == E_INVALIDARG
,
292 "Expected E_INVALIDARG: %d\n", GetLastError());
293 /* This has no effect, but "succeeds" on XP */
294 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo",
295 "1.2.3.4.5.6.7.8.9.10", NULL
, NULL
);
296 ok(ret
, "Expected pseudo-success, got %d\n", GetLastError());
297 SetLastError(0xdeadbeef);
298 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
299 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
300 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
302 skip("Need admin rights\n");
305 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
306 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
307 "1.2.3.4.5.6.7.8.9.10");
308 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
309 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "bogus",
310 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
311 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
312 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "bogus",
313 "1.2.3.4.5.6.7.8.9.10");
314 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
315 /* Unwanted Cryptography\OID\EncodingType 1\bogus\ will still be there */
316 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
317 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 1\\bogus"),
318 "Could not delete bogus key\n");
319 /* Shouldn't have effect but registry keys are created */
320 ret
= CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
321 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
322 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
323 ret
= CryptUnregisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
324 "1.2.3.4.5.6.7.8.9.10");
325 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
326 /* Check with bogus encoding type. Registry keys are still created */
327 ret
= CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
328 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
329 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
330 ret
= CryptUnregisterOIDFunction(0, "CryptDllEncodeObject",
331 "1.2.3.4.5.6.7.8.9.10");
332 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
333 /* Unwanted Cryptography\OID\EncodingType 0\CryptDllEncodeObject\
334 * will still be there
336 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
337 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllEncodeObject"),
338 "Could not delete CryptDllEncodeObject key\n");
339 /* This is written with value 3 verbatim. Thus, the encoding type isn't
340 * (for now) treated as a mask. Registry keys are created.
342 ret
= CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
343 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
344 ok(ret
, "CryptRegisterOIDFunction failed: %d\n", GetLastError());
345 ret
= CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
346 "1.2.3.4.5.6.7.8.9.10");
347 ok(ret
, "CryptUnregisterOIDFunction failed: %d\n", GetLastError());
348 /* Unwanted Cryptography\OID\EncodingType 3\CryptDllEncodeObject
349 * will still be there.
351 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
352 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3\\CryptDllEncodeObject"),
353 "Could not delete CryptDllEncodeObject key\n");
354 ok(!RegDeleteKeyA(HKEY_LOCAL_MACHINE
,
355 "SOFTWARE\\Microsoft\\Cryptography\\OID\\EncodingType 3"),
356 "Could not delete 'EncodingType 3' key\n");
359 static void test_registerDefaultOIDFunction(void)
361 static const char fmt
[] =
362 "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\DEFAULT";
363 static const char func
[] = "CertDllOpenStoreProv";
369 ret
= CryptRegisterDefaultOIDFunction(0, NULL
, 0, NULL
);
370 ok(!ret
&& GetLastError() == E_INVALIDARG
,
371 "Expected E_INVALIDARG, got %08x\n", GetLastError());
372 /* This succeeds on WinXP, although the bogus entry is unusable.
373 ret = CryptRegisterDefaultOIDFunction(0, NULL, 0, bogusDll);
375 /* Register one at index 0 */
376 SetLastError(0xdeadbeef);
377 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
379 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
381 skip("Need admin rights\n");
384 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
385 /* Reregistering should fail */
386 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
388 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
389 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
390 /* Registering the same one at index 1 should also fail */
391 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
393 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
394 "Expected ERROR_FILE_EXISTS, got %08x\n", GetLastError());
395 /* Registering a different one at index 1 succeeds */
396 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 1,
398 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
399 sprintf(buf
, fmt
, 0, func
);
400 rc
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, buf
, &key
);
401 ok(rc
== 0, "Expected key to exist, RegOpenKeyA failed: %ld\n", rc
);
404 static const CHAR dllA
[] = "Dll";
405 static const CHAR bogusDll_A
[] = "bogus.dll";
406 static const CHAR bogus2Dll_A
[] = "bogus2.dll";
407 CHAR dllBuf
[MAX_PATH
];
411 size
= sizeof(dllBuf
) / sizeof(dllBuf
[0]);
412 rc
= RegQueryValueExA(key
, dllA
, NULL
, &type
, (LPBYTE
)dllBuf
, &size
);
414 "Expected Dll value to exist, RegQueryValueExA failed: %ld\n", rc
);
415 ok(type
== REG_MULTI_SZ
, "Expected type REG_MULTI_SZ, got %d\n", type
);
416 /* bogusDll was registered first, so that should be first */
418 ok(!lstrcmpiA(ptr
, bogusDll_A
), "Unexpected dll\n");
419 ptr
+= lstrlenA(ptr
) + 1;
420 ok(!lstrcmpiA(ptr
, bogus2Dll_A
), "Unexpected dll\n");
423 /* Unregister both of them */
424 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
426 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
428 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
430 ok(ret
, "CryptUnregisterDefaultOIDFunction failed: %08x\n",
432 /* Now that they're both unregistered, unregistering should fail */
433 ret
= CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv",
435 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
436 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
438 /* Repeat a few tests on the normal encoding type */
439 ret
= CryptRegisterDefaultOIDFunction(X509_ASN_ENCODING
,
440 "CertDllOpenStoreProv", 0, bogusDll
);
441 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
442 "CertDllOpenStoreProv", bogusDll
);
443 ok(ret
, "CryptUnregisterDefaultOIDFunction failed\n");
444 ret
= CryptUnregisterDefaultOIDFunction(X509_ASN_ENCODING
,
445 "CertDllOpenStoreProv", bogusDll
);
446 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
447 "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
450 static void test_getDefaultOIDFunctionAddress(void)
453 HCRYPTOIDFUNCSET set
;
455 HCRYPTOIDFUNCADDR hFuncAddr
;
458 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, NULL);
459 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr, NULL);
460 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, NULL, &hFuncAddr);
461 ret = CryptGetDefaultOIDFunctionAddress(0, 0, NULL, 0, &funcAddr,
464 set
= CryptInitOIDFunctionSet("CertDllOpenStoreProv", 0);
465 ok(set
!= 0, "CryptInitOIDFunctionSet failed: %d\n", GetLastError());
466 /* This crashes if hFuncAddr is not 0 to begin with */
468 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
470 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
471 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
472 /* This fails with the normal encoding too, so built-in functions aren't
475 ret
= CryptGetDefaultOIDFunctionAddress(set
, X509_ASN_ENCODING
, NULL
, 0,
476 &funcAddr
, &hFuncAddr
);
477 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
478 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
480 /* Even with a registered dll, this fails (since the dll doesn't exist) */
481 SetLastError(0xdeadbeef);
482 ret
= CryptRegisterDefaultOIDFunction(0, "CertDllOpenStoreProv", 0,
484 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
485 skip("Need admin rights\n");
487 ok(ret
, "CryptRegisterDefaultOIDFunction failed: %08x\n", GetLastError());
488 ret
= CryptGetDefaultOIDFunctionAddress(set
, 0, NULL
, 0, &funcAddr
,
490 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
491 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
492 CryptUnregisterDefaultOIDFunction(0, "CertDllOpenStoreProv", bogusDll
);
495 static BOOL WINAPI
countOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
501 static BOOL WINAPI
noOidInfo(PCCRYPT_OID_INFO pInfo
, void *pvArg
)
506 static void test_enumOIDInfo(void)
511 if (!pCryptEnumOIDInfo
)
513 skip("CryptEnumOIDInfo() is not available\n");
518 ret = pCryptEnumOIDInfo(7, 0, NULL, NULL);
521 /* Silly tests, check that more than one thing is enumerated */
522 ret
= pCryptEnumOIDInfo(0, 0, &count
, countOidInfo
);
523 ok(ret
&& count
> 0, "Expected more than item enumerated\n");
524 ret
= pCryptEnumOIDInfo(0, 0, NULL
, noOidInfo
);
525 ok(!ret
, "Expected FALSE\n");
528 static void test_findOIDInfo(void)
530 static WCHAR sha1
[] = { 's','h','a','1',0 };
531 static CHAR oid_rsa_md5
[] = szOID_RSA_MD5
;
532 ALG_ID alg
= CALG_SHA1
;
533 ALG_ID algs
[2] = { CALG_MD5
, CALG_RSA_SIGN
};
534 PCCRYPT_OID_INFO info
;
536 info
= CryptFindOIDInfo(0, NULL
, 0);
537 ok(info
== NULL
, "Expected NULL\n");
538 info
= CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY
, oid_rsa_md5
, 0);
539 ok(info
!= NULL
, "Expected to find szOID_RSA_MD5\n");
542 ok(!strcmp(info
->pszOID
, szOID_RSA_MD5
), "Expected %s, got %s\n",
543 szOID_RSA_MD5
, info
->pszOID
);
544 ok(U(*info
).Algid
== CALG_MD5
, "Expected CALG_MD5, got %d\n",
547 info
= CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY
, sha1
, 0);
548 ok(info
!= NULL
, "Expected to find sha1\n");
551 ok(!strcmp(info
->pszOID
, szOID_OIWSEC_sha1
), "Expected %s, got %s\n",
552 szOID_OIWSEC_sha1
, info
->pszOID
);
553 ok(U(*info
).Algid
== CALG_SHA1
, "Expected CALG_SHA1, got %d\n",
556 info
= CryptFindOIDInfo(CRYPT_OID_INFO_ALGID_KEY
, &alg
, 0);
557 ok(info
!= NULL
, "Expected to find sha1\n");
560 ok(!strcmp(info
->pszOID
, szOID_OIWSEC_sha1
), "Expected %s, got %s\n",
561 szOID_OIWSEC_sha1
, info
->pszOID
);
562 ok(U(*info
).Algid
== CALG_SHA1
, "Expected CALG_SHA1, got %d\n",
565 info
= CryptFindOIDInfo(CRYPT_OID_INFO_SIGN_KEY
, algs
, 0);
566 ok(info
!= NULL
, "Expected to find md5RSA\n");
569 ok(!strcmp(info
->pszOID
, szOID_RSA_MD5RSA
), "Expected %s, got %s\n",
570 szOID_RSA_MD5RSA
, info
->pszOID
);
571 ok(U(*info
).Algid
== CALG_MD5
, "Expected CALG_MD5, got %d\n",
578 HMODULE hCrypt32
= GetModuleHandleA("crypt32.dll");
579 pCryptEnumOIDInfo
= (void*)GetProcAddress(hCrypt32
, "CryptEnumOIDInfo");
585 test_oidFunctionSet();
586 test_installOIDFunctionAddress();
587 test_registerOIDFunction();
588 test_registerDefaultOIDFunction();
589 test_getDefaultOIDFunctionAddress();