wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / crypt32 / tests / base64.c
blob64148342b2b2e9586bb46c65a510ca47e1742c84
1 /*
2 * Unit test suite for crypt32.dll's CryptStringToBinary and CryptBinaryToString
3 * functions.
5 * Copyright 2006 Juan Lang
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.
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.
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
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <windows.h>
24 #include <wincrypt.h>
26 #include "wine/heap.h"
27 #include "wine/test.h"
29 #define CERT_HEADER "-----BEGIN CERTIFICATE-----\r\n"
30 #define ALT_CERT_HEADER "-----BEGIN This is some arbitrary text that goes on and on-----\r\n"
31 #define CERT_TRAILER "-----END CERTIFICATE-----\r\n"
32 #define ALT_CERT_TRAILER "-----END More arbitrary text------\r\n"
33 #define CERT_REQUEST_HEADER "-----BEGIN NEW CERTIFICATE REQUEST-----\r\n"
34 #define CERT_REQUEST_TRAILER "-----END NEW CERTIFICATE REQUEST-----\r\n"
35 #define X509_HEADER "-----BEGIN X509 CRL-----\r\n"
36 #define X509_TRAILER "-----END X509 CRL-----\r\n"
37 #define CERT_HEADER_NOCR "-----BEGIN CERTIFICATE-----\n"
38 #define CERT_TRAILER_NOCR "-----END CERTIFICATE-----\n"
39 #define CERT_REQUEST_HEADER_NOCR "-----BEGIN NEW CERTIFICATE REQUEST-----\n"
40 #define CERT_REQUEST_TRAILER_NOCR "-----END NEW CERTIFICATE REQUEST-----\n"
41 #define X509_HEADER_NOCR "-----BEGIN X509 CRL-----\n"
42 #define X509_TRAILER_NOCR "-----END X509 CRL-----\n"
44 struct BinTests
46 const BYTE *toEncode;
47 DWORD toEncodeLen;
48 const char *base64;
51 static const BYTE toEncode1[] = { 0 };
52 static const BYTE toEncode2[] = { 1,2 };
53 /* static const BYTE toEncode3[] = { 1,2,3 }; */
54 static const BYTE toEncode4[] =
55 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
56 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
57 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
58 static const BYTE toEncode5[] =
59 "abcdefghijlkmnopqrstuvwxyz01234567890ABCDEFGHI";
61 static const struct BinTests tests[] = {
62 { toEncode1, sizeof(toEncode1), "AA==\r\n", },
63 { toEncode2, sizeof(toEncode2), "AQI=\r\n", },
64 /* { toEncode3, sizeof(toEncode3), "AQID\r\n", }, This test fails on Vista. */
65 { toEncode4, sizeof(toEncode4),
66 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISUpL\r\n"
67 "TE1OT1BRUlNUVVZXWFlaMDEyMzQ1Njc4OTBhYmNkZWZnaGlqbGttbm9wcXJzdHV2\r\n"
68 "d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\r\n"
69 "Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\r\n"
70 "SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\r\n" },
71 { toEncode5, sizeof(toEncode5),
72 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISQA=\r\n" },
75 static const struct BinTests testsNoCR[] = {
76 { toEncode1, sizeof(toEncode1), "AA==\n", },
77 { toEncode2, sizeof(toEncode2), "AQI=\n", },
78 /* { toEncode3, sizeof(toEncode3), "AQID\n", }, This test fails on Vista. */
79 { toEncode4, sizeof(toEncode4),
80 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISUpL\n"
81 "TE1OT1BRUlNUVVZXWFlaMDEyMzQ1Njc4OTBhYmNkZWZnaGlqbGttbm9wcXJzdHV2\n"
82 "d3h5ejAxMjM0NTY3ODkwQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2\n"
83 "Nzg5MGFiY2RlZmdoaWpsa21ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OTBBQkNERUZH\n"
84 "SElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NTY3ODkwAA==\n" },
85 { toEncode5, sizeof(toEncode5),
86 "YWJjZGVmZ2hpamxrbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5MEFCQ0RFRkdISQA=\n" },
89 static WCHAR *strdupAtoW(const char *str)
91 WCHAR *ret = NULL;
92 DWORD len;
94 if (!str) return ret;
95 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
96 ret = heap_alloc(len * sizeof(WCHAR));
97 if (ret)
98 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
99 return ret;
102 static void encodeAndCompareBase64_A(const BYTE *toEncode, DWORD toEncodeLen,
103 DWORD format, const char *expected, const char *header, const char *trailer)
105 DWORD strLen, strLen2, required;
106 const char *ptr;
107 LPSTR str = NULL;
108 BOOL ret;
110 required = strlen(expected) + 1;
111 if (header)
112 required += strlen(header);
113 if (trailer)
114 required += strlen(trailer);
116 strLen = 0;
117 ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen);
118 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
119 ok(strLen == required, "Unexpected required length %u, expected %u.\n", required, strLen);
121 strLen2 = strLen;
122 ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen2);
123 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
124 ok(strLen == strLen2, "Unexpected required length %u, expected %u.\n", strLen2, strLen);
126 strLen2 = strLen - 1;
127 ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, NULL, &strLen2);
128 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
129 ok(strLen == strLen2, "Unexpected required length %u, expected %u.\n", strLen2, strLen);
131 str = heap_alloc(strLen);
133 /* Partially filled output buffer. */
134 strLen2 = strLen - 1;
135 str[0] = 0x12;
136 ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, str, &strLen2);
137 ok((!ret && GetLastError() == ERROR_MORE_DATA) || broken(ret) /* XP */, "CryptBinaryToStringA failed %d, error %d.\n",
138 ret, GetLastError());
139 ok(strLen2 == strLen || broken(strLen2 == strLen - 1), "Expected length %d, got %d\n", strLen, strLen2);
140 if (header)
141 ok(str[0] == header[0], "Unexpected buffer contents %#x.\n", str[0]);
142 else
143 ok(str[0] == expected[0], "Unexpected buffer contents %#x.\n", str[0]);
144 strLen2 = strLen;
145 ret = CryptBinaryToStringA(toEncode, toEncodeLen, format, str, &strLen2);
146 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
147 ok(strLen2 == strLen - 1, "Expected length %d, got %d\n", strLen - 1, strLen2);
149 ptr = str;
150 if (header)
152 ok(!strncmp(header, ptr, strlen(header)), "Expected header %s, got %s\n", header, ptr);
153 ptr += strlen(header);
155 ok(!strncmp(expected, ptr, strlen(expected)), "Expected %s, got %s\n", expected, ptr);
156 ptr += strlen(expected);
157 if (trailer)
158 ok(!strncmp(trailer, ptr, strlen(trailer)), "Expected trailer %s, got %s\n", trailer, ptr);
160 heap_free(str);
163 static void encode_compare_base64_W(const BYTE *toEncode, DWORD toEncodeLen, DWORD format,
164 const WCHAR *expected, const char *header, const char *trailer)
166 WCHAR *headerW, *trailerW, required;
167 DWORD strLen, strLen2;
168 WCHAR *strW = NULL;
169 const WCHAR *ptr;
170 BOOL ret;
172 required = lstrlenW(expected) + 1;
173 if (header)
174 required += strlen(header);
175 if (trailer)
176 required += strlen(trailer);
178 strLen = 0;
179 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen);
180 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
181 ok(strLen == required, "Unexpected required length %u, expected %u.\n", strLen, required);
183 /* Same call with non-zero length value. */
184 strLen2 = strLen;
185 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
186 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
187 ok(strLen == strLen2, "Unexpected required length.\n");
189 strLen2 = strLen - 1;
190 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
191 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
192 ok(strLen == strLen2, "Unexpected required length.\n");
194 strLen2 = strLen - 1;
195 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, NULL, &strLen2);
196 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
197 ok(strLen == strLen2, "Unexpected required length.\n");
199 strW = heap_alloc(strLen * sizeof(WCHAR));
201 headerW = strdupAtoW(header);
202 trailerW = strdupAtoW(trailer);
204 strLen2 = strLen - 1;
205 strW[0] = 0x1234;
206 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, strW, &strLen2);
207 ok((!ret && GetLastError() == ERROR_MORE_DATA) || broken(ret) /* XP */, "CryptBinaryToStringW failed, %d, error %d\n",
208 ret, GetLastError());
209 if (headerW)
210 ok(strW[0] == 0x1234, "Unexpected buffer contents %#x.\n", strW[0]);
211 else
212 ok(strW[0] == 0x1234 || broken(strW[0] != 0x1234) /* XP */, "Unexpected buffer contents %#x.\n", strW[0]);
214 strLen2 = strLen;
215 ret = CryptBinaryToStringW(toEncode, toEncodeLen, format, strW, &strLen2);
216 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
218 ok(strLen2 == strLen - 1, "Expected length %d, got %d\n", strLen - 1, strLen);
220 ptr = strW;
221 if (headerW)
223 ok(!memcmp(headerW, ptr, lstrlenW(headerW)), "Expected header %s, got %s.\n", wine_dbgstr_w(headerW),
224 wine_dbgstr_w(ptr));
225 ptr += lstrlenW(headerW);
227 ok(!memcmp(expected, ptr, lstrlenW(expected)), "Expected %s, got %s.\n", wine_dbgstr_w(expected),
228 wine_dbgstr_w(ptr));
229 ptr += lstrlenW(expected);
230 if (trailerW)
231 ok(!memcmp(trailerW, ptr, lstrlenW(trailerW)), "Expected trailer %s, got %s.\n", wine_dbgstr_w(trailerW),
232 wine_dbgstr_w(ptr));
234 heap_free(strW);
235 heap_free(headerW);
236 heap_free(trailerW);
239 static DWORD binary_to_hex_len(DWORD binary_len, DWORD flags)
241 DWORD strLen2;
243 strLen2 = binary_len * 3; /* spaces + terminating \0 */
245 if (flags & CRYPT_STRING_NOCR)
247 strLen2 += (binary_len + 7) / 16; /* space every 16 characters */
248 strLen2 += 1; /* terminating \n */
250 else if (!(flags & CRYPT_STRING_NOCRLF))
252 strLen2 += (binary_len + 7) / 16; /* space every 16 characters */
253 strLen2 += binary_len / 16 + 1; /* LF every 16 characters + terminating \r */
255 if (binary_len % 16)
256 strLen2 += 1; /* terminating \n */
259 return strLen2;
262 static void test_CryptBinaryToString(void)
264 static const DWORD flags[] = { 0, CRYPT_STRING_NOCR, CRYPT_STRING_NOCRLF };
265 static const DWORD sizes[] = { 3, 4, 7, 8, 12, 15, 16, 17, 256 };
266 static const WCHAR hexdig[] = L"0123456789abcdef";
267 BYTE input[256 * sizeof(WCHAR)];
268 DWORD strLen, strLen2, i, j, k;
269 WCHAR *hex, *cmp, *ptr;
270 BOOL ret;
272 ret = CryptBinaryToStringA(NULL, 0, 0, NULL, NULL);
273 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
274 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
276 strLen = 123;
277 ret = CryptBinaryToStringA(NULL, 0, 0, NULL, &strLen);
278 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
279 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
280 ok(strLen == 123, "Unexpected length.\n");
282 if (0)
283 ret = CryptBinaryToStringW(NULL, 0, 0, NULL, NULL);
285 strLen = 123;
286 ret = CryptBinaryToStringW(NULL, 0, 0, NULL, &strLen);
287 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Unexpected error %d\n", GetLastError());
288 ok(strLen == 123, "Unexpected length.\n");
290 for (i = 0; i < ARRAY_SIZE(tests); i++)
292 WCHAR *strW, *encodedW;
293 LPSTR str = NULL;
294 BOOL ret;
296 strLen = 0;
297 ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
298 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
299 ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
301 strLen2 = strLen;
302 str = heap_alloc(strLen);
303 ret = CryptBinaryToStringA(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, str, &strLen2);
304 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
305 ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
306 ok(!memcmp(str, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
307 heap_free(str);
309 strLen = 0;
310 ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, NULL, &strLen);
311 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
312 ok(strLen == tests[i].toEncodeLen, "Unexpected required length %u.\n", strLen);
314 strLen2 = strLen;
315 strW = heap_alloc(strLen);
316 ret = CryptBinaryToStringW(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BINARY, strW, &strLen2);
317 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
318 ok(strLen == strLen2, "Expected length %u, got %u\n", strLen, strLen2);
319 ok(!memcmp(strW, tests[i].toEncode, tests[i].toEncodeLen), "Unexpected value\n");
320 heap_free(strW);
322 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64,
323 tests[i].base64, NULL, NULL);
324 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64HEADER,
325 tests[i].base64, CERT_HEADER, CERT_TRAILER);
326 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64REQUESTHEADER,
327 tests[i].base64, CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
328 encodeAndCompareBase64_A(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64X509CRLHEADER,
329 tests[i].base64, X509_HEADER, X509_TRAILER);
331 encodedW = strdupAtoW(tests[i].base64);
333 encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64, encodedW, NULL, NULL);
334 encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64HEADER, encodedW,
335 CERT_HEADER, CERT_TRAILER);
336 encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64REQUESTHEADER,
337 encodedW, CERT_REQUEST_HEADER, CERT_REQUEST_TRAILER);
338 encode_compare_base64_W(tests[i].toEncode, tests[i].toEncodeLen, CRYPT_STRING_BASE64X509CRLHEADER, encodedW,
339 X509_HEADER, X509_TRAILER);
341 heap_free(encodedW);
344 for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
346 LPSTR str = NULL;
347 WCHAR *encodedW;
348 BOOL ret;
350 ret = CryptBinaryToStringA(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
351 CRYPT_STRING_BINARY | CRYPT_STRING_NOCR, NULL, &strLen);
352 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
354 strLen2 = strLen;
355 str = heap_alloc(strLen);
356 ret = CryptBinaryToStringA(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
357 CRYPT_STRING_BINARY | CRYPT_STRING_NOCR, str, &strLen2);
358 ok(ret, "CryptBinaryToStringA failed: %d\n", GetLastError());
359 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen, strLen2);
360 ok(!memcmp(str, testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen), "Unexpected value\n");
361 heap_free(str);
363 encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR,
364 testsNoCR[i].base64, NULL, NULL);
365 encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
366 CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
367 encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
368 CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, CERT_REQUEST_HEADER_NOCR,
369 CERT_REQUEST_TRAILER_NOCR);
370 encodeAndCompareBase64_A(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
371 CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR, testsNoCR[i].base64, X509_HEADER_NOCR, X509_TRAILER_NOCR);
373 encodedW = strdupAtoW(testsNoCR[i].base64);
375 encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
376 CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR, encodedW, NULL, NULL);
377 encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
378 CRYPT_STRING_BASE64HEADER | CRYPT_STRING_NOCR, encodedW, CERT_HEADER_NOCR, CERT_TRAILER_NOCR);
379 encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
380 CRYPT_STRING_BASE64REQUESTHEADER | CRYPT_STRING_NOCR, encodedW, CERT_REQUEST_HEADER_NOCR,
381 CERT_REQUEST_TRAILER_NOCR);
382 encode_compare_base64_W(testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen,
383 CRYPT_STRING_BASE64X509CRLHEADER | CRYPT_STRING_NOCR, encodedW,
384 X509_HEADER_NOCR, X509_TRAILER_NOCR);
386 heap_free(encodedW);
389 /* Systems that don't support HEXRAW format convert to BASE64 instead - 3 bytes in -> 4 chars + crlf + 1 null out. */
390 strLen = 0;
391 ret = CryptBinaryToStringW(input, 3, CRYPT_STRING_HEXRAW, NULL, &strLen);
392 ok(ret, "Failed to get string length.\n");
393 ok(strLen == 9 || broken(strLen == 7), "Unexpected string length %d.\n", strLen);
394 if (strLen == 7)
396 win_skip("CryptBinaryToString(HEXRAW) not supported\n");
397 return;
400 for (i = 0; i < sizeof(input) / sizeof(WCHAR); i++)
401 ((WCHAR *)input)[i] = i;
403 for (i = 0; i < ARRAY_SIZE(flags); i++)
405 strLen = 0;
406 ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i], NULL, &strLen);
407 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
408 ok(strLen > 0, "Unexpected string length.\n");
410 strLen = ~0;
411 ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i],
412 NULL, &strLen);
413 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
414 if (flags[i] & CRYPT_STRING_NOCRLF)
415 strLen2 = 0;
416 else if (flags[i] & CRYPT_STRING_NOCR)
417 strLen2 = 1;
418 else
419 strLen2 = 2;
420 strLen2 += sizeof(input) * 2 + 1;
421 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen2, strLen);
423 hex = heap_alloc(strLen * sizeof(WCHAR));
424 memset(hex, 0xcc, strLen * sizeof(WCHAR));
425 ptr = cmp = heap_alloc(strLen * sizeof(WCHAR));
426 for (j = 0; j < ARRAY_SIZE(input); j++)
428 *ptr++ = hexdig[(input[j] >> 4) & 0xf];
429 *ptr++ = hexdig[input[j] & 0xf];
431 if (flags[i] & CRYPT_STRING_NOCR)
433 *ptr++ = '\n';
435 else if (!(flags[i] & CRYPT_STRING_NOCRLF))
437 *ptr++ = '\r';
438 *ptr++ = '\n';
440 *ptr++ = 0;
441 ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i],
442 hex, &strLen);
443 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
444 strLen2--;
445 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen, strLen2);
446 ok(!memcmp(hex, cmp, strLen * sizeof(WCHAR)), "Unexpected value\n");
448 /* adjusts size if buffer too big */
449 strLen *= 2;
450 ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i],
451 hex, &strLen);
452 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
453 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen, strLen2);
455 /* no writes if buffer too small */
456 strLen /= 2;
457 strLen2 /= 2;
458 memset(hex, 0xcc, strLen * sizeof(WCHAR));
459 memset(cmp, 0xcc, strLen * sizeof(WCHAR));
460 SetLastError(0xdeadbeef);
461 ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i],
462 hex, &strLen);
463 ok(!ret && GetLastError() == ERROR_MORE_DATA,"Expected ERROR_MORE_DATA, got ret=%d le=%u\n",
464 ret, GetLastError());
465 ok(strLen == strLen2, "Expected length %d, got %d\n", strLen, strLen2);
466 ok(!memcmp(hex, cmp, strLen * sizeof(WCHAR)), "Unexpected value\n");
468 heap_free(hex);
469 heap_free(cmp);
472 for (k = 0; k < ARRAY_SIZE(sizes); k++)
473 for (i = 0; i < ARRAY_SIZE(flags); i++)
475 strLen = 0;
476 ret = CryptBinaryToStringW(input, sizes[k], CRYPT_STRING_HEX | flags[i], NULL, &strLen);
477 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
478 ok(strLen > 0, "Unexpected string length.\n");
480 strLen = ~0;
481 ret = CryptBinaryToStringW(input, sizes[k], CRYPT_STRING_HEX | flags[i], NULL, &strLen);
482 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
483 strLen2 = binary_to_hex_len(sizes[k], CRYPT_STRING_HEX | flags[i]);
484 ok(strLen == strLen2, "%u: Expected length %d, got %d\n", i, strLen2, strLen);
486 hex = heap_alloc(strLen * sizeof(WCHAR) + 256);
487 memset(hex, 0xcc, strLen * sizeof(WCHAR));
489 ptr = cmp = heap_alloc(strLen * sizeof(WCHAR) + 256);
490 for (j = 0; j < sizes[k]; j++)
492 *ptr++ = hexdig[(input[j] >> 4) & 0xf];
493 *ptr++ = hexdig[input[j] & 0xf];
495 if (j >= sizes[k] - 1) break;
497 if (j && !(flags[i] & CRYPT_STRING_NOCRLF))
500 if (!((j + 1) % 16))
502 if (flags[i] & CRYPT_STRING_NOCR)
504 *ptr++ = '\n';
506 else
508 *ptr++ = '\r';
509 *ptr++ = '\n';
511 continue;
513 else if (!((j + 1) % 8))
514 *ptr++ = ' ';
517 *ptr++ = ' ';
520 if (flags[i] & CRYPT_STRING_NOCR)
522 *ptr++ = '\n';
524 else if (!(flags[i] & CRYPT_STRING_NOCRLF))
526 *ptr++ = '\r';
527 *ptr++ = '\n';
529 *ptr++ = 0;
531 ret = CryptBinaryToStringW(input, sizes[k], CRYPT_STRING_HEX | flags[i], hex, &strLen);
532 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
533 strLen2--;
534 ok(strLen == strLen2, "%u: Expected length %d, got %d\n", i, strLen, strLen2);
535 ok(!memcmp(hex, cmp, strLen * sizeof(WCHAR)), "%u: got %s\n", i, wine_dbgstr_wn(hex, strLen));
537 /* adjusts size if buffer too big */
538 strLen *= 2;
539 ret = CryptBinaryToStringW(input, sizes[k], CRYPT_STRING_HEX | flags[i], hex, &strLen);
540 ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
541 ok(strLen == strLen2, "%u: Expected length %d, got %d\n", i, strLen, strLen2);
543 /* no writes if buffer too small */
544 strLen /= 2;
545 strLen2 /= 2;
546 memset(hex, 0xcc, strLen * sizeof(WCHAR));
547 memset(cmp, 0xcc, strLen * sizeof(WCHAR));
548 SetLastError(0xdeadbeef);
549 ret = CryptBinaryToStringW(input, sizes[k], CRYPT_STRING_HEX | flags[i], hex, &strLen);
550 ok(!ret && GetLastError() == ERROR_MORE_DATA,"Expected ERROR_MORE_DATA, got ret=%d le=%u\n",
551 ret, GetLastError());
552 ok(strLen == strLen2, "%u: Expected length %d, got %d\n", i, strLen, strLen2);
553 ok(!memcmp(hex, cmp, strLen * sizeof(WCHAR)), "%u: got %s\n", i, wine_dbgstr_wn(hex, strLen));
555 heap_free(hex);
556 heap_free(cmp);
560 static void decodeAndCompareBase64_A(LPCSTR toDecode, LPCSTR header,
561 LPCSTR trailer, DWORD useFormat, DWORD expectedFormat, const BYTE *expected,
562 DWORD expectedLen)
564 static const char garbage[] = "garbage\r\n";
565 LPSTR str;
566 DWORD len = strlen(toDecode) + strlen(garbage) + 1;
568 if (header)
569 len += strlen(header);
570 if (trailer)
571 len += strlen(trailer);
572 str = HeapAlloc(GetProcessHeap(), 0, len);
573 if (str)
575 LPBYTE buf;
576 DWORD bufLen = 0;
577 BOOL ret;
579 if (header)
580 strcpy(str, header);
581 else
582 *str = 0;
583 strcat(str, toDecode);
584 if (trailer)
585 strcat(str, trailer);
586 ret = CryptStringToBinaryA(str, 0, useFormat, NULL, &bufLen, NULL,
587 NULL);
588 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
589 buf = HeapAlloc(GetProcessHeap(), 0, bufLen);
590 if (buf)
592 DWORD skipped, usedFormat;
594 /* check as normal, make sure last two parameters are optional */
595 ret = CryptStringToBinaryA(str, 0, useFormat, buf, &bufLen, NULL,
596 NULL);
597 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
598 ok(bufLen == expectedLen,
599 "Expected length %d, got %d\n", expectedLen, bufLen);
600 ok(!memcmp(buf, expected, bufLen), "Unexpected value\n");
601 /* check last two params */
602 ret = CryptStringToBinaryA(str, 0, useFormat, buf, &bufLen,
603 &skipped, &usedFormat);
604 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
605 ok(skipped == 0, "Expected skipped 0, got %d\n", skipped);
606 ok(usedFormat == expectedFormat, "Expected format %d, got %d\n",
607 expectedFormat, usedFormat);
608 HeapFree(GetProcessHeap(), 0, buf);
611 /* Check again, but with garbage up front */
612 strcpy(str, garbage);
613 if (header)
614 strcat(str, header);
615 strcat(str, toDecode);
616 if (trailer)
617 strcat(str, trailer);
618 ret = CryptStringToBinaryA(str, 0, useFormat, NULL, &bufLen, NULL,
619 NULL);
620 /* expect failure with no header, and success with one */
621 if (header)
622 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
623 else
624 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
625 "Expected !ret and last error ERROR_INVALID_DATA, got ret=%d, error=%d\n", ret, GetLastError());
626 if (ret)
628 buf = HeapAlloc(GetProcessHeap(), 0, bufLen);
629 if (buf)
631 DWORD skipped, usedFormat;
633 ret = CryptStringToBinaryA(str, 0, useFormat, buf, &bufLen,
634 &skipped, &usedFormat);
635 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
636 ok(skipped == strlen(garbage),
637 "Expected %d characters of \"%s\" skipped when trying format %08x, got %d (used format is %08x)\n",
638 lstrlenA(garbage), str, useFormat, skipped, usedFormat);
639 HeapFree(GetProcessHeap(), 0, buf);
642 HeapFree(GetProcessHeap(), 0, str);
646 static void decodeBase64WithLenFmtW(LPCSTR strA, int len, DWORD fmt, BOOL retA,
647 const BYTE *bufA, DWORD bufLenA, DWORD fmtUsedA)
649 BYTE buf[8] = {0};
650 DWORD bufLen = sizeof(buf)-1, fmtUsed = 0xdeadbeef;
651 BOOL ret;
652 WCHAR strW[64];
653 int i;
654 for (i = 0; (strW[i] = strA[i]) != 0; ++i);
655 ret = CryptStringToBinaryW(strW, len, fmt, buf, &bufLen, NULL, &fmtUsed);
656 ok(ret == retA && bufLen == bufLenA && memcmp(bufA, buf, bufLen) == 0
657 && fmtUsed == fmtUsedA, "base64 \"%s\" len %d: W and A differ\n", strA, len);
660 static void decodeBase64WithLenFmt(LPCSTR str, int len, DWORD fmt, LPCSTR expected, int le, BOOL isBroken)
662 BYTE buf[8] = {0};
663 DWORD bufLen = sizeof(buf)-1, fmtUsed = 0xdeadbeef;
664 BOOL ret;
665 SetLastError(0xdeadbeef);
666 ret = CryptStringToBinaryA(str, len, fmt, buf, &bufLen, NULL, &fmtUsed);
667 buf[bufLen] = 0;
668 if (expected) {
669 BOOL correct = ret && strcmp(expected, (char*)buf) == 0;
670 ok(correct || (isBroken && broken(!ret)),
671 "base64 \"%s\" len %d: expected \"%s\", got \"%s\" (ret %d, le %d)\n",
672 str, len, expected, (char*)buf, ret, GetLastError());
673 if (correct)
674 ok(fmtUsed == fmt, "base64 \"%s\" len %d: expected fmt %d, used %d\n",
675 str, len, fmt, fmtUsed);
676 } else {
677 ok(!ret && GetLastError() == le,
678 "base64 \"%s\" len %d: expected failure, got \"%s\" (ret %d, le %d)\n",
679 str, len, (char*)buf, ret, GetLastError());
682 decodeBase64WithLenFmtW(str, len, fmt, ret, buf, bufLen, fmtUsed);
685 static void decodeBase64WithLenBroken(LPCSTR str, int len, LPCSTR expected, int le)
687 decodeBase64WithLenFmt(str, len, CRYPT_STRING_BASE64, expected, le, TRUE);
690 static void decodeBase64WithLen(LPCSTR str, int len, LPCSTR expected, int le)
692 decodeBase64WithLenFmt(str, len, CRYPT_STRING_BASE64, expected, le, FALSE);
695 static void decodeBase64WithFmt(LPCSTR str, DWORD fmt, LPCSTR expected, int le)
697 decodeBase64WithLenFmt(str, 0, fmt, expected, le, FALSE);
700 struct BadString
702 const char *str;
703 DWORD format;
706 static const struct BadString badStrings[] = {
707 { "-----BEGIN X509 CRL-----\r\nAA==\r\n", CRYPT_STRING_BASE64X509CRLHEADER },
710 static void testStringToBinaryA(void)
712 BOOL ret;
713 DWORD bufLen = 0, i;
714 BYTE buf[8];
716 ret = CryptStringToBinaryA(NULL, 0, 0, NULL, NULL, NULL, NULL);
717 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
718 "Expected ERROR_INVALID_PARAMETER, got ret=%d le=%u\n", ret, GetLastError());
719 ret = CryptStringToBinaryA(NULL, 0, 0, NULL, &bufLen, NULL, NULL);
720 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
721 "Expected ERROR_INVALID_PARAMETER, got ret=%d le=%u\n", ret, GetLastError());
722 /* Bogus format */
723 ret = CryptStringToBinaryA(tests[0].base64, 0, 0, NULL, &bufLen, NULL,
724 NULL);
725 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
726 "Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
727 /* Decoding doesn't expect the NOCR flag to be specified */
728 ret = CryptStringToBinaryA(tests[0].base64, 1,
729 CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR, NULL, &bufLen, NULL, NULL);
730 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
731 "Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
732 /* Bad strings */
733 for (i = 0; i < ARRAY_SIZE(badStrings); i++)
735 bufLen = 0;
736 ret = CryptStringToBinaryA(badStrings[i].str, 0, badStrings[i].format,
737 NULL, &bufLen, NULL, NULL);
738 ok(!ret && GetLastError() == ERROR_INVALID_DATA,
739 "%d: Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", i, ret, GetLastError());
741 /* Weird base64 strings (invalid padding, extra white-space etc.) */
742 decodeBase64WithLen("V=", 0, 0, ERROR_INVALID_DATA);
743 decodeBase64WithLen("VV=", 0, 0, ERROR_INVALID_DATA);
744 decodeBase64WithLen("V==", 0, 0, ERROR_INVALID_DATA);
745 decodeBase64WithLen("V=", 2, 0, ERROR_INVALID_DATA);
746 decodeBase64WithLen("VV=", 3, 0, ERROR_INVALID_DATA);
747 decodeBase64WithLen("V==", 3, 0, ERROR_INVALID_DATA);
748 decodeBase64WithLenBroken("V", 0, "T", 0);
749 decodeBase64WithLenBroken("VV", 0, "U", 0);
750 decodeBase64WithLenBroken("VVV", 0, "UU", 0);
751 decodeBase64WithLen("V", 1, "T", 0);
752 decodeBase64WithLen("VV", 2, "U", 0);
753 decodeBase64WithLen("VVV", 3, "UU", 0);
754 decodeBase64WithLen("V===", 0, "T", 0);
755 decodeBase64WithLen("V========", 0, "T", 0);
756 decodeBase64WithLen("V===", 4, "T", 0);
757 decodeBase64WithLen("V\nVVV", 0, "UUU", 0);
758 decodeBase64WithLen("VV\nVV", 0, "UUU", 0);
759 decodeBase64WithLen("VVV\nV", 0, "UUU", 0);
760 decodeBase64WithLen("V\nVVV", 5, "UUU", 0);
761 decodeBase64WithLen("VV\nVV", 5, "UUU", 0);
762 decodeBase64WithLen("VVV\nV", 5, "UUU", 0);
763 decodeBase64WithLen("VV VV", 0, "UUU", 0);
764 decodeBase64WithLen("V===VVVV", 0, "T", 0);
765 decodeBase64WithLen("VV==VVVV", 0, "U", 0);
766 decodeBase64WithLen("VVV=VVVV", 0, "UU", 0);
767 decodeBase64WithLen("VVVV=VVVV", 0, "UUU", 0);
768 decodeBase64WithLen("V===VVVV", 8, "T", 0);
769 decodeBase64WithLen("VV==VVVV", 8, "U", 0);
770 decodeBase64WithLen("VVV=VVVV", 8, "UU", 0);
771 decodeBase64WithLen("VVVV=VVVV", 8, "UUU", 0);
773 decodeBase64WithFmt("-----BEGIN-----VVVV-----END-----", CRYPT_STRING_BASE64HEADER, 0, ERROR_INVALID_DATA);
774 decodeBase64WithFmt("-----BEGIN-----VVVV-----END -----", CRYPT_STRING_BASE64HEADER, 0, ERROR_INVALID_DATA);
775 decodeBase64WithFmt("-----BEGIN -----VVVV-----END-----", CRYPT_STRING_BASE64HEADER, 0, ERROR_INVALID_DATA);
776 decodeBase64WithFmt("-----BEGIN -----VVVV-----END -----", CRYPT_STRING_BASE64HEADER, "UUU", 0);
778 decodeBase64WithFmt("-----BEGIN -----V-----END -----", CRYPT_STRING_BASE64HEADER, "T", 0);
779 decodeBase64WithFmt("-----BEGIN foo-----V-----END -----", CRYPT_STRING_BASE64HEADER, "T", 0);
780 decodeBase64WithFmt("-----BEGIN foo-----V-----END foo-----", CRYPT_STRING_BASE64HEADER, "T", 0);
781 decodeBase64WithFmt("-----BEGIN -----V-----END foo-----", CRYPT_STRING_BASE64HEADER, "T", 0);
782 decodeBase64WithFmt("-----BEGIN -----V-----END -----", CRYPT_STRING_BASE64X509CRLHEADER, "T", 0);
783 decodeBase64WithFmt("-----BEGIN foo-----V-----END -----", CRYPT_STRING_BASE64X509CRLHEADER, "T", 0);
784 decodeBase64WithFmt("-----BEGIN foo-----V-----END foo-----", CRYPT_STRING_BASE64X509CRLHEADER, "T", 0);
785 decodeBase64WithFmt("-----BEGIN -----V-----END foo-----", CRYPT_STRING_BASE64X509CRLHEADER, "T", 0);
786 decodeBase64WithFmt("-----BEGIN -----V-----END -----", CRYPT_STRING_BASE64REQUESTHEADER, "T", 0);
787 decodeBase64WithFmt("-----BEGIN foo-----V-----END -----", CRYPT_STRING_BASE64REQUESTHEADER, "T", 0);
788 decodeBase64WithFmt("-----BEGIN foo-----V-----END foo-----", CRYPT_STRING_BASE64REQUESTHEADER, "T", 0);
789 decodeBase64WithFmt("-----BEGIN -----V-----END foo-----", CRYPT_STRING_BASE64REQUESTHEADER, "T", 0);
791 /* Too small buffer */
792 buf[0] = 0;
793 bufLen = 4;
794 ret = CryptStringToBinaryA("VVVVVVVV", 8, CRYPT_STRING_BASE64, (BYTE*)buf, &bufLen, NULL, NULL);
795 ok(!ret && bufLen == 4 && buf[0] == 0,
796 "Expected ret 0, bufLen 4, buf[0] '\\0', got ret %d, bufLen %d, buf[0] '%c'\n",
797 ret, bufLen, buf[0]);
799 /* Good strings */
800 for (i = 0; i < ARRAY_SIZE(tests); i++)
802 bufLen = 0;
803 /* Bogus length--oddly enough, that succeeds, even though it's not
804 * properly padded.
806 ret = CryptStringToBinaryA(tests[i].base64, 1, CRYPT_STRING_BASE64,
807 NULL, &bufLen, NULL, NULL);
808 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
809 /* Check with the precise format */
810 decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
811 CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, tests[i].toEncode,
812 tests[i].toEncodeLen);
813 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
814 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
815 tests[i].toEncode, tests[i].toEncodeLen);
816 decodeAndCompareBase64_A(tests[i].base64, ALT_CERT_HEADER, ALT_CERT_TRAILER,
817 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
818 tests[i].toEncode, tests[i].toEncodeLen);
819 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
820 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
821 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
822 tests[i].toEncodeLen);
823 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
824 CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
825 tests[i].toEncode, tests[i].toEncodeLen);
826 /* And check with the "any" formats */
827 decodeAndCompareBase64_A(tests[i].base64, NULL, NULL,
828 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, tests[i].toEncode,
829 tests[i].toEncodeLen);
830 /* Don't check with no header and the string_any format, that'll
831 * always succeed.
833 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
834 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
835 tests[i].toEncodeLen);
836 decodeAndCompareBase64_A(tests[i].base64, CERT_HEADER, CERT_TRAILER,
837 CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, tests[i].toEncode,
838 tests[i].toEncodeLen);
839 /* oddly, these seem to decode using the wrong format
840 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
841 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64_ANY,
842 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
843 tests[i].toEncodeLen);
844 decodeAndCompareBase64_A(tests[i].base64, CERT_REQUEST_HEADER,
845 CERT_REQUEST_TRAILER, CRYPT_STRING_ANY,
846 CRYPT_STRING_BASE64REQUESTHEADER, tests[i].toEncode,
847 tests[i].toEncodeLen);
848 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
849 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64X509CRLHEADER,
850 tests[i].toEncode, tests[i].toEncodeLen);
851 decodeAndCompareBase64_A(tests[i].base64, X509_HEADER, X509_TRAILER,
852 CRYPT_STRING_ANY, CRYPT_STRING_BASE64X509CRLHEADER, tests[i].toEncode,
853 tests[i].toEncodeLen);
856 /* And again, with no CR--decoding handles this automatically */
857 for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
859 bufLen = 0;
860 /* Bogus length--oddly enough, that succeeds, even though it's not
861 * properly padded.
863 ret = CryptStringToBinaryA(testsNoCR[i].base64, 1, CRYPT_STRING_BASE64,
864 NULL, &bufLen, NULL, NULL);
865 ok(ret, "CryptStringToBinaryA failed: %d\n", GetLastError());
866 /* Check with the precise format */
867 decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
868 CRYPT_STRING_BASE64, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
869 testsNoCR[i].toEncodeLen);
870 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
871 CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64HEADER,
872 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
873 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_REQUEST_HEADER,
874 CERT_REQUEST_TRAILER, CRYPT_STRING_BASE64REQUESTHEADER,
875 CRYPT_STRING_BASE64REQUESTHEADER, testsNoCR[i].toEncode,
876 testsNoCR[i].toEncodeLen);
877 decodeAndCompareBase64_A(testsNoCR[i].base64, X509_HEADER, X509_TRAILER,
878 CRYPT_STRING_BASE64X509CRLHEADER, CRYPT_STRING_BASE64X509CRLHEADER,
879 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
880 /* And check with the "any" formats */
881 decodeAndCompareBase64_A(testsNoCR[i].base64, NULL, NULL,
882 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64, testsNoCR[i].toEncode,
883 testsNoCR[i].toEncodeLen);
884 /* Don't check with no header and the string_any format, that'll
885 * always succeed.
887 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
888 CRYPT_STRING_BASE64_ANY, CRYPT_STRING_BASE64HEADER,
889 testsNoCR[i].toEncode, testsNoCR[i].toEncodeLen);
890 decodeAndCompareBase64_A(testsNoCR[i].base64, CERT_HEADER, CERT_TRAILER,
891 CRYPT_STRING_ANY, CRYPT_STRING_BASE64HEADER, testsNoCR[i].toEncode,
892 testsNoCR[i].toEncodeLen);
896 START_TEST(base64)
898 test_CryptBinaryToString();
899 testStringToBinaryA();