crypt32: Test and correct CryptVerifyCertificateSignature.
[wine] / dlls / crypt32 / tests / 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  { "A\r\nA\r\n=\r\n=\r\n", CRYPT_STRING_BASE64 },
310  { "AA\r\n=\r\n=\r\n", CRYPT_STRING_BASE64 },
311  { "AA=\r\n=\r\n", CRYPT_STRING_BASE64 },
312  { "-----BEGIN X509 CRL-----\r\nAA==\r\n", CRYPT_STRING_BASE64X509CRLHEADER },
313 };
314
315 static void testStringToBinaryA(void)
316 {
317     BOOL ret;
318     DWORD bufLen = 0, i;
319
320     ret = pCryptStringToBinaryA(NULL, 0, 0, NULL, NULL, NULL, NULL);
321     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
322      "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
323     ret = pCryptStringToBinaryA(NULL, 0, 0, NULL, &bufLen, NULL, NULL);
324     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
325      "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
326     /* Bogus format */
327     ret = pCryptStringToBinaryA(tests[0].base64, 0, 0, NULL, &bufLen, NULL,
328      NULL);
329     ok(!ret && GetLastError() == ERROR_INVALID_DATA,
330      "Expected ERROR_INVALID_DATA, got %d\n", GetLastError());
331     /* Decoding doesn't expect the NOCR flag to be specified */
332     ret = pCryptStringToBinaryA(tests[0].base64, 1,
333      CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR, NULL, &bufLen, NULL, NULL);
334     ok(!ret && GetLastError() == ERROR_INVALID_DATA,
335      "Expected ERROR_INVALID_DATA, got %d\n", GetLastError());
336     /* Bad strings */
337     for (i = 0; i < sizeof(badStrings) / sizeof(badStrings[0]); i++)
338     {
339         bufLen = 0;
340         ret = pCryptStringToBinaryA(badStrings[i].str, 0, badStrings[i].format,
341          NULL, &bufLen, NULL, NULL);
342         ok(!ret && GetLastError() == ERROR_INVALID_DATA,
343          "Expected ERROR_INVALID_DATA, got %d\n", GetLastError());
344     }
345     /* Good strings */
346     for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
347     {
348         bufLen = 0;
349         /* Bogus length--oddly enough, that succeeds, even though it's not
350          * properly padded.
351          */
352         ret = pCryptStringToBinaryA(tests[i].base64, 1, CRYPT_STRING_BASE64,
353          NULL, &bufLen, NULL, NULL);
354         todo_wine ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
355         /* Check with the precise format */
356         decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
357          CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, tests[i].toEncode,
358          tests[i].toEncodeLen);
359         decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
360          CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
361          tests[i].toEncode, tests[i].toEncodeLen);
362         decodeAndCompareBase64_A(tests[i].base64, ALT_CERT_HEADER, ALT_CERT_TRAILER,
363          CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
364          tests[i].toEncode, tests[i].toEncodeLen);
365         decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
366          CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
367          CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
368          tests[i].toEncodeLen);
369         decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
370          CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
371          tests[i].toEncode, tests[i].toEncodeLen);
372         /* And check with the "any" formats */
373         decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
374          CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, tests[i].toEncode,
375          tests[i].toEncodeLen);
376         /* Don't check with no header and the string_any format, that'll
377          * always succeed.
378          */
379         decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
380          CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
381          tests[i].toEncodeLen);
382         decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
383          CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
384          tests[i].toEncodeLen);
385         /* oddly, these seem to decode using the wrong format
386         decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
387          CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64_ANY,
388          CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
389          tests[i].toEncodeLen);
390         decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
391          CERT_REQUEST_TRAILER, CRYPT_STRING_ANY,
392          CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
393          tests[i].toEncodeLen);
394         decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
395          CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64X509CRLHEADER,
396          tests[i].toEncode, tests[i].toEncodeLen);
397         decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
398          CRYPT_STRING_ANY, CRYPT_STRING_BASE64X509CRLHEADER, tests[i].toEncode,
399          tests[i].toEncodeLen);
400          */
401     }
402     /* And again, with no CR--decoding handles this automatically */
403     for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
404     {
405         bufLen = 0;
406         /* Bogus length--oddly enough, that succeeds, even though it's not
407          * properly padded.
408          */
409         ret = pCryptStringToBinaryA(testsNoCR[i].base64, 1, CRYPT_STRING_BASE64,
410          NULL, &bufLen, NULL, NULL);
411         todo_wine ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
412         /* Check with the precise format */
413         decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
414          CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
415          testsNoCR[i].toEncodeLen);
416         decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
417          CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
418          testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
419         decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_REQUEST_HEADER,
420          CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
421          CRYPT_STRING_BASE64REQUESTHEADER, testsNoCR[i].toEncode,
422          testsNoCR[i].toEncodeLen);
423         decodeAndCompareBase64_A(testsNoCR[i].base64, X509_HEADER, X509_TRAILER,
424          CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
425          testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
426         /* And check with the "any" formats */
427         decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
428          CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
429          testsNoCR[i].toEncodeLen);
430         /* Don't check with no header and the string_any format, that'll
431          * always succeed.
432          */
433         decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
434          CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER,
435          testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
436         decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
437          CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, testsNoCR[i].toEncode,
438          testsNoCR[i].toEncodeLen);
439     }
440 }
441
442 START_TEST(base64)
443 {
444     HMODULE lib = GetModuleHandleA("crypt32");
445
446     pCryptBinaryToStringA = (void *)GetProcAddress(lib, "CryptBinaryToStringA");
447     pCryptStringToBinaryA = (void *)GetProcAddress(lib, "CryptStringToBinaryA");
448
449     if (pCryptBinaryToStringA)
450         testBinaryToStringA();
451     else
452         win_skip("CryptBinaryToStringA is not available\n");
453
454     if (pCryptStringToBinaryA)
455         testStringToBinaryA();
456     else
457         win_skip("CryptStringToBinaryA is not available\n");
458 }