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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/test.h"
29 static void test_oidFunctionSet(void)
31 HCRYPTOIDFUNCSET set1, set2;
37 set = CryptInitOIDFunctionSet(NULL, 0);
40 /* The name doesn't mean much */
41 set1 = CryptInitOIDFunctionSet("funky", 0);
42 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
46 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, NULL);
47 ret = CryptGetDefaultOIDDllList(NULL, 0, NULL, &size);
50 ret = CryptGetDefaultOIDDllList(set1, 0, NULL, &size);
51 ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n", GetLastError());
54 buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
57 ret = CryptGetDefaultOIDDllList(set1, 0, buf, &size);
58 ok(ret, "CryptGetDefaultOIDDllList failed: %08lx\n",
60 ok(!*buf, "Expected empty DLL list\n");
61 HeapFree(GetProcessHeap(), 0, buf);
66 /* MSDN says flags must be 0, but it's not checked */
67 set1 = CryptInitOIDFunctionSet("", 1);
68 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
69 set2 = CryptInitOIDFunctionSet("", 0);
70 ok(set2 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
71 /* There isn't a free function, so there must be only one set per name to
72 * limit leaks. (I guess the sets are freed when crypt32 is unloaded.)
74 ok(set1 == set2, "Expected identical sets\n");
77 /* The empty name function set used here seems to correspond to
82 /* There's no installed function for a built-in encoding. */
83 set1 = CryptInitOIDFunctionSet("CryptDllEncodeObject", 0);
84 ok(set1 != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
88 HCRYPTOIDFUNCADDR hFuncAddr;
90 ret = CryptGetOIDFunctionAddress(set1, X509_ASN_ENCODING, X509_CERT, 0,
91 &funcAddr, &hFuncAddr);
92 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
93 "Expected ERROR_FILE_NOT_FOUND, got %08lx\n", GetLastError());
97 typedef int (*funcY)(int);
99 static int funky(int x)
104 static void test_installOIDFunctionAddress(void)
107 CRYPT_OID_FUNC_ENTRY entry = { CRYPT_DEFAULT_OID, funky };
108 HCRYPTOIDFUNCSET set;
111 ret = CryptInstallOIDFunctionAddress(NULL, 0, NULL, 0, NULL, 0);
114 /* Installing zero functions should work */
115 SetLastError(0xdeadbeef);
116 ret = CryptInstallOIDFunctionAddress(NULL, 0, "CryptDllEncodeObject", 0,
118 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
121 /* The function name doesn't much matter */
122 SetLastError(0xdeadbeef);
123 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 0, NULL, 0);
124 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
126 SetLastError(0xdeadbeef);
127 entry.pszOID = X509_CERT;
128 ret = CryptInstallOIDFunctionAddress(NULL, 0, "OhSoFunky", 1, &entry, 0);
129 ok(ret && GetLastError() == 0xdeadbeef, "Expected success, got %08lx\n",
131 set = CryptInitOIDFunctionSet("OhSoFunky", 0);
132 ok(set != 0, "CryptInitOIDFunctionSet failed: %08lx\n", GetLastError());
135 funcY funcAddr = NULL;
136 HCRYPTOIDFUNCADDR hFuncAddr = NULL;
139 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0, NULL,
142 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, 0, 0,
143 (void **)&funcAddr, &hFuncAddr);
144 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
145 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
146 ret = CryptGetOIDFunctionAddress(set, X509_ASN_ENCODING, X509_CERT, 0,
147 (void **)&funcAddr, &hFuncAddr);
148 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
149 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
150 ret = CryptGetOIDFunctionAddress(set, 0, X509_CERT, 0,
151 (void **)&funcAddr, &hFuncAddr);
152 ok(ret, "CryptGetOIDFunctionAddress failed: %ld\n", GetLastError());
155 int y = funcAddr(0xabadc0da);
157 ok(y == 0xabadc0da, "Unexpected return (%d) from function\n", y);
158 CryptFreeOIDFunctionAddress(hFuncAddr, 0);
163 static void test_registerOIDFunction(void)
165 static const WCHAR bogusDll[] = { 'b','o','g','u','s','.','d','l','l',0 };
168 /* oddly, this succeeds under WinXP; the function name key is merely
169 * omitted. This may be a side effect of the registry code, I don't know.
170 * I don't check it because I doubt anyone would depend on it.
171 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
172 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
174 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
175 * HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)
177 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo", NULL, bogusDll,
179 ok(!ret && GetLastError() == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
180 "Expected ERROR_INVALID_PARAMETER: %ld\n", GetLastError());
181 /* This has no effect, but "succeeds" on XP */
182 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "foo",
183 "1.2.3.4.5.6.7.8.9.10", NULL, NULL);
184 ok(ret, "Expected pseudo-success, got %ld\n", GetLastError());
185 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
186 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
187 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
188 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "CryptDllEncodeObject",
189 "1.2.3.4.5.6.7.8.9.10");
190 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
191 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, "bogus",
192 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
193 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
194 ret = CryptUnregisterOIDFunction(X509_ASN_ENCODING, "bogus",
195 "1.2.3.4.5.6.7.8.9.10");
196 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
197 /* This has no effect */
198 ret = CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING, "CryptDllEncodeObject",
199 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
200 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
201 /* Check with bogus encoding type: */
202 ret = CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
203 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
204 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
205 /* This is written with value 3 verbatim. Thus, the encoding type isn't
206 * (for now) treated as a mask.
208 ret = CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
209 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
210 ok(ret, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
211 ret = CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
212 "1.2.3.4.5.6.7.8.9.10");
213 ok(ret, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
218 test_oidFunctionSet();
219 test_installOIDFunctionAddress();
220 test_registerOIDFunction();