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