[CRYPT32_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / rostests / winetests / crypt32 / base64.c
1 /*
2 * Unit test suite for crypt32.dll's CryptStringToBinary and CryptBinaryToString
3 * functions.
4 *
5 * Copyright 2006 Juan Lang
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 //#include <stdio.h>
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 //#include <winerror.h>
26 #include <wincrypt.h>
27
28 #include <wine/test.h>
29
30 #define CERT_HEADER "-----BEGIN CERTIFICATE-----\r\n"
31 #define ALT_CERT_HEADER "-----BEGIN This is some arbitrary text that goes on and on-----\r\n"
32 #define CERT_TRAILER "-----END CERTIFICATE-----\r\n"
33 #define ALT_CERT_TRAILER "-----END More arbitrary text------\r\n"
34 #define CERT_REQUEST_HEADER "-----BEGIN NEW CERTIFICATE REQUEST-----\r\n"
35 #define CERT_REQUEST_TRAILER "-----END NEW CERTIFICATE REQUEST-----\r\n"
36 #define X509_HEADER "-----BEGIN X509 CRL-----\r\n"
37 #define X509_TRAILER "-----END X509 CRL-----\r\n"
38 #define CERT_HEADER_NOCR "-----BEGIN CERTIFICATE-----\n"
39 #define CERT_TRAILER_NOCR "-----END CERTIFICATE-----\n"
40 #define CERT_REQUEST_HEADER_NOCR "-----BEGIN NEW CERTIFICATE REQUEST-----\n"
41 #define CERT_REQUEST_TRAILER_NOCR "-----END NEW CERTIFICATE REQUEST-----\n"
42 #define X509_HEADER_NOCR "-----BEGIN X509 CRL-----\n"
43 #define X509_TRAILER_NOCR "-----END X509 CRL-----\n"
44
45 static BOOL (WINAPI *pCryptBinaryToStringA)(const BYTE *pbBinary,
46 DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString);
47 static BOOL (WINAPI *pCryptStringToBinaryA)(LPCSTR pszString,
48 DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary,
49 DWORD *pdwSkip, DWORD *pdwFlags);
50
51 struct BinTests
52 {
53 const BYTE *toEncode;
54 DWORD toEncodeLen;
55 const char *base64;
56 };
57
58 static const BYTE toEncode1[] = { 0 };
59 static const BYTE toEncode2[] = { 1,2 };
60 /* static const BYTE toEncode3[] = { 1,2,3 }; */
61 static const BYTE toEncode4[] =
62 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
63 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
64 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
65
66 static const struct BinTests tests[] = {
67 { toEncode1, sizeof(toEncode1), "AA==\r\n", },
68 { toEncode2, sizeof(toEncode2), "AQI=\r\n", },
69 /* { toEncode3, sizeof(toEncode3), "AQID\r\n", }, This test fails on Vista. */
70 { toEncode4, sizeof(toEncode4),
71 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISUpL\r\n"
72 "TE1OT1BRUlNUVVZXWFlaMDEyMzQ1Njc4OTBhYmNkZWZnaGlqbGttbm9wcXJzdHV2\r\n"
73 "d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\r\n"
74 "Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\r\n"
75 "SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\r\n" },
76 };
77
78 static const struct BinTests testsNoCR[] = {
79 { toEncode1, sizeof(toEncode1), "AA==\n", },
80 { toEncode2, sizeof(toEncode2), "AQI=\n", },
81 /* { toEncode3, sizeof(toEncode3), "AQID\n", }, This test fails on Vista. */
82 { toEncode4, sizeof(toEncode4),
83 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISUpL\n"
84 "TE1OT1BRUlNUVVZXWFlaMDEyMzQ1Njc4OTBhYmNkZWZnaGlqbGttbm9wcXJzdHV2\n"
85 "d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\n"
86 "Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\n"
87 "SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\n" },
88 };
89
90 static void encodeAndCompareBase64_A(const BYTE *toEncode, DWORD toEncodeLen,
91 DWORD format, const char *expected, const char *header, const char *trailer)
92 {
93 DWORD strLen = 0;
94 LPSTR str = NULL;
95 BOOL ret;
96
97 ret = pCryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen);
98 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
99 str = HeapAlloc(GetProcessHeap(), 0, strLen);
100 if (str)
101 {
102 DWORD strLen2 = strLen;
103 LPCSTR ptr = str;
104
105 ret = pCryptBinaryToStringA(toEncode, toEncodeLen, format, str,
106 &strLen2);
107 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
108 ok(strLen2 == strLen - 1, "Expected length %d, got %d\n",
109 strLen - 1, strLen);
110 if (header)
111 {
112 ok(!strncmp(header, ptr, strlen(header)),
113 "Expected header %s, got %s\n", header, ptr);
114 ptr += strlen(header);
115 }
116 ok(!strncmp(expected, ptr, strlen(expected)),
117 "Expected %s, got %s\n", expected, ptr);
118 ptr += strlen(expected);
119 if (trailer)
120 ok(!strncmp(trailer, ptr, strlen(trailer)),
121 "Expected trailer %s, got %s\n", trailer, ptr);
122 HeapFree(GetProcessHeap(), 0, str);
123 }
124 }
125
126 static void testBinaryToStringA(void)
127 {
128 BOOL ret;
129 DWORD strLen = 0, i;
130
131 ret = pCryptBinaryToStringA(NULL, 0, 0, NULL, NULL);
132 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
133 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
134 ret = pCryptBinaryToStringA(NULL, 0, 0, NULL, &strLen);
135 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
136 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
137 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
138 {
139 DWORD strLen = 0;
140 LPSTR str = NULL;
141 BOOL ret;
142
143 ret = pCryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen,
144 CRYPT_STRING_BINARY, NULL, &strLen);
145 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
146 str = HeapAlloc(GetProcessHeap(), 0, strLen);
147 if (str)
148 {
149 DWORD strLen2 = strLen;
150
151 ret = pCryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen,
152 CRYPT_STRING_BINARY, str, &strLen2);
153 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
154 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen,
155 strLen2);
156 ok(!memcmp(str, tests[i].toEncode, tests[i].toEncodeLen),
157 "Unexpected value\n");
158 HeapFree(GetProcessHeap(), 0, str);
159 }
160 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
161 CRYPT_STRING_BASE64, tests[i].base64, NULL, NULL);
162 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
163 CRYPT_STRING_BASE64HEADER, tests[i].base64, CERT_HEADER,
164 CERT_TRAILER);
165 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
166 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].base64,
167 CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
168 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen,
169 CRYPT_STRING_BASE64X509CRLHEADER, tests[i].base64, X509_HEADER,
170 X509_TRAILER);
171 }
172 for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
173 {
174 DWORD strLen = 0;
175 LPSTR str = NULL;
176 BOOL ret;
177
178 ret = pCryptBinaryToStringA(testsNoCR[i].toEncode,
179 testsNoCR[i].toEncodeLen, CRYPT_STRING_BINARY | CRYPT_STRING_NOCR,
180 NULL, &strLen);
181 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
182 str = HeapAlloc(GetProcessHeap(), 0, strLen);
183 if (str)
184 {
185 DWORD strLen2 = strLen;
186
187 ret = pCryptBinaryToStringA(testsNoCR[i].toEncode,
188 testsNoCR[i].toEncodeLen, CRYPT_STRING_BINARY | CRYPT_STRING_NOCR,
189 str, &strLen2);
190 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
191 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen,
192 strLen2);
193 ok(!memcmp(str, testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen),
194 "Unexpected value\n");
195 HeapFree(GetProcessHeap(), 0, str);
196 }
197 encodeAndCompareBase64_A(testsNoCR[i].toEncode,
198 testsNoCR[i].toEncodeLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR,
199 testsNoCR[i].base64, NULL, NULL);
200 encodeAndCompareBase64_A(testsNoCR[i].toEncode,
201 testsNoCR[i].toEncodeLen,
202 CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64,
203 CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
204 encodeAndCompareBase64_A(testsNoCR[i].toEncode,
205 testsNoCR[i].toEncodeLen,
206 CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR,
207 testsNoCR[i].base64, CERT_REQUEST_HEADER_NOCR,
208 CERT_REQUEST_TRAILER_NOCR);
209 encodeAndCompareBase64_A(testsNoCR[i].toEncode,
210 testsNoCR[i].toEncodeLen,
211 CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR,
212 testsNoCR[i].base64, X509_HEADER_NOCR, X509_TRAILER_NOCR);
213 }
214 }
215
216 static void decodeAndCompareBase64_A(LPCSTR toDecode, LPCSTR header,
217 LPCSTR trailer, DWORD useFormat, DWORD expectedFormat, const BYTE *expected,
218 DWORD expectedLen)
219 {
220 static const char garbage[] = "garbage\r\n";
221 LPSTR str;
222 DWORD len = strlen(toDecode) + strlen(garbage) + 1;
223
224 if (header)
225 len += strlen(header);
226 if (trailer)
227 len += strlen(trailer);
228 str = HeapAlloc(GetProcessHeap(), 0, len);
229 if (str)
230 {
231 LPBYTE buf;
232 DWORD bufLen = 0;
233 BOOL ret;
234
235 if (header)
236 strcpy(str, header);
237 else
238 *str = 0;
239 strcat(str, toDecode);
240 if (trailer)
241 strcat(str, trailer);
242 ret = pCryptStringToBinaryA(str, 0, useFormat, NULL, &bufLen, NULL,
243 NULL);
244 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
245 buf = HeapAlloc(GetProcessHeap(), 0, bufLen);
246 if (buf)
247 {
248 DWORD skipped, usedFormat;
249
250 /* check as normal, make sure last two parameters are optional */
251 ret = pCryptStringToBinaryA(str, 0, useFormat, buf, &bufLen, NULL,
252 NULL);
253 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
254 ok(bufLen == expectedLen,
255 "Expected length %d, got %d\n", expectedLen, bufLen);
256 ok(!memcmp(buf, expected, bufLen), "Unexpected value\n");
257 /* check last two params */
258 ret = pCryptStringToBinaryA(str, 0, useFormat, buf, &bufLen,
259 &skipped, &usedFormat);
260 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
261 ok(skipped == 0, "Expected skipped 0, got %d\n", skipped);
262 ok(usedFormat == expectedFormat, "Expected format %d, got %d\n",
263 expectedFormat, usedFormat);
264 HeapFree(GetProcessHeap(), 0, buf);
265 }
266
267 /* Check again, but with garbage up front */
268 strcpy(str, garbage);
269 if (header)
270 strcat(str, header);
271 strcat(str, toDecode);
272 if (trailer)
273 strcat(str, trailer);
274 ret = pCryptStringToBinaryA(str, 0, useFormat, NULL, &bufLen, NULL,
275 NULL);
276 /* expect failure with no header, and success with one */
277 if (header)
278 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
279 else
280 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
281 "Expected !ret and last error ERROR_INVALID_DATA, got ret=%d, error=%d\n", ret, GetLastError());
282 if (ret)
283 {
284 buf = HeapAlloc(GetProcessHeap(), 0, bufLen);
285 if (buf)
286 {
287 DWORD skipped, usedFormat;
288
289 ret = pCryptStringToBinaryA(str, 0, useFormat, buf, &bufLen,
290 &skipped, &usedFormat);
291 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
292 ok(skipped == strlen(garbage),
293 "Expected %d characters of \"%s\" skipped when trying format %08x, got %d (used format is %08x)\n",
294 lstrlenA(garbage), str, useFormat, skipped, usedFormat);
295 HeapFree(GetProcessHeap(), 0, buf);
296 }
297 }
298 HeapFree(GetProcessHeap(), 0, str);
299 }
300 }
301
302 struct BadString
303 {
304 const char *str;
305 DWORD format;
306 };
307
308 static const struct BadString badStrings[] = {
309 { "-----BEGIN X509 CRL-----\r\nAA==\r\n", CRYPT_STRING_BASE64X509CRLHEADER },
310 };
311
312 static void testStringToBinaryA(void)
313 {
314 BOOL ret;
315 DWORD bufLen = 0, i;
316
317 ret = pCryptStringToBinaryA(NULL, 0, 0, NULL, NULL, NULL, NULL);
318 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
319 "Expected ERROR_INVALID_PARAMETER, got ret=%d le=%u\n", ret, GetLastError());
320 ret = pCryptStringToBinaryA(NULL, 0, 0, NULL, &bufLen, NULL, NULL);
321 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
322 "Expected ERROR_INVALID_PARAMETER, got ret=%d le=%u\n", ret, GetLastError());
323 /* Bogus format */
324 ret = pCryptStringToBinaryA(tests[0].base64, 0, 0, NULL, &bufLen, NULL,
325 NULL);
326 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
327 "Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
328 /* Decoding doesn't expect the NOCR flag to be specified */
329 ret = pCryptStringToBinaryA(tests[0].base64, 1,
330 CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR, NULL, &bufLen, NULL, NULL);
331 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
332 "Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
333 /* Bad strings */
334 for (i = 0; i < sizeof(badStrings) / sizeof(badStrings[0]); i++)
335 {
336 bufLen = 0;
337 ret = pCryptStringToBinaryA(badStrings[i].str, 0, badStrings[i].format,
338 NULL, &bufLen, NULL, NULL);
339 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
340 "%d: Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", i, ret, GetLastError());
341 }
342 /* Good strings */
343 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
344 {
345 bufLen = 0;
346 /* Bogus length--oddly enough, that succeeds, even though it's not
347 * properly padded.
348 */
349 ret = pCryptStringToBinaryA(tests[i].base64, 1, CRYPT_STRING_BASE64,
350 NULL, &bufLen, NULL, NULL);
351 todo_wine ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
352 /* Check with the precise format */
353 decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
354 CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, tests[i].toEncode,
355 tests[i].toEncodeLen);
356 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
357 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
358 tests[i].toEncode, tests[i].toEncodeLen);
359 decodeAndCompareBase64_A(tests[i].base64, ALT_CERT_HEADER, ALT_CERT_TRAILER,
360 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
361 tests[i].toEncode, tests[i].toEncodeLen);
362 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
363 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
364 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
365 tests[i].toEncodeLen);
366 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
367 CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
368 tests[i].toEncode, tests[i].toEncodeLen);
369 /* And check with the "any" formats */
370 decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
371 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, tests[i].toEncode,
372 tests[i].toEncodeLen);
373 /* Don't check with no header and the string_any format, that'll
374 * always succeed.
375 */
376 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
377 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
378 tests[i].toEncodeLen);
379 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
380 CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
381 tests[i].toEncodeLen);
382 /* oddly, these seem to decode using the wrong format
383 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
384 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64_ANY,
385 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
386 tests[i].toEncodeLen);
387 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
388 CERT_REQUEST_TRAILER, CRYPT_STRING_ANY,
389 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
390 tests[i].toEncodeLen);
391 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
392 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64X509CRLHEADER,
393 tests[i].toEncode, tests[i].toEncodeLen);
394 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
395 CRYPT_STRING_ANY, CRYPT_STRING_BASE64X509CRLHEADER, tests[i].toEncode,
396 tests[i].toEncodeLen);
397 */
398 }
399 /* And again, with no CR--decoding handles this automatically */
400 for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
401 {
402 bufLen = 0;
403 /* Bogus length--oddly enough, that succeeds, even though it's not
404 * properly padded.
405 */
406 ret = pCryptStringToBinaryA(testsNoCR[i].base64, 1, CRYPT_STRING_BASE64,
407 NULL, &bufLen, NULL, NULL);
408 todo_wine ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
409 /* Check with the precise format */
410 decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
411 CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
412 testsNoCR[i].toEncodeLen);
413 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
414 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
415 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
416 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_REQUEST_HEADER,
417 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
418 CRYPT_STRING_BASE64REQUESTHEADER, testsNoCR[i].toEncode,
419 testsNoCR[i].toEncodeLen);
420 decodeAndCompareBase64_A(testsNoCR[i].base64, X509_HEADER, X509_TRAILER,
421 CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
422 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
423 /* And check with the "any" formats */
424 decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
425 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
426 testsNoCR[i].toEncodeLen);
427 /* Don't check with no header and the string_any format, that'll
428 * always succeed.
429 */
430 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
431 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER,
432 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
433 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
434 CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, testsNoCR[i].toEncode,
435 testsNoCR[i].toEncodeLen);
436 }
437 }
438
439 START_TEST(base64)
440 {
441 HMODULE lib = GetModuleHandleA("crypt32");
442
443 pCryptBinaryToStringA = (void *)GetProcAddress(lib, "CryptBinaryToStringA");
444 pCryptStringToBinaryA = (void *)GetProcAddress(lib, "CryptStringToBinaryA");
445
446 if (pCryptBinaryToStringA)
447 testBinaryToStringA();
448 else
449 win_skip("CryptBinaryToStringA is not available\n");
450
451 if (pCryptStringToBinaryA)
452 testStringToBinaryA();
453 else
454 win_skip("CryptStringToBinaryA is not available\n");
455 }