ReactOS 0.4.17-dev-470-gf9e3448
base64.c
Go to the documentation of this file.
1/*
2 * base64 encoder/decoder
3 *
4 * Copyright 2005 by Kai Blin
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
22#include <stdarg.h>
23#include "windef.h"
24#include "winbase.h"
25#include "winerror.h"
26#include "wincrypt.h"
27#include "wine/debug.h"
28
30
31#define CERT_HEADER "-----BEGIN CERTIFICATE-----"
32#define CERT_HEADER_START "-----BEGIN "
33#define CERT_DELIMITER "-----"
34#define CERT_TRAILER "-----END CERTIFICATE-----"
35#define CERT_TRAILER_START "-----END "
36#define CERT_REQUEST_HEADER "-----BEGIN NEW CERTIFICATE REQUEST-----"
37#define CERT_REQUEST_TRAILER "-----END NEW CERTIFICATE REQUEST-----"
38#define X509_HEADER "-----BEGIN X509 CRL-----"
39#define X509_TRAILER "-----END X509 CRL-----"
40
41static const WCHAR CERT_HEADER_W[] = L"-----BEGIN CERTIFICATE-----";
42static const WCHAR CERT_HEADER_START_W[] = L"-----BEGIN ";
43static const WCHAR CERT_DELIMITER_W[] = L"-----";
44static const WCHAR CERT_TRAILER_W[] = L"-----END CERTIFICATE-----";
45static const WCHAR CERT_TRAILER_START_W[] = L"-----END ";
46static const WCHAR CERT_REQUEST_HEADER_W[] = L"-----BEGIN NEW CERTIFICATE REQUEST-----";
47static const WCHAR CERT_REQUEST_TRAILER_W[] = L"-----END NEW CERTIFICATE REQUEST-----";
48static const WCHAR X509_HEADER_W[] = L"-----BEGIN X509 CRL-----";
49static const WCHAR X509_TRAILER_W[] = L"-----END X509 CRL-----";
50
51static const char b64[] =
52"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
53
54typedef BOOL (*BinaryToStringAFunc)(const BYTE *pbBinary,
55 DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString);
56typedef BOOL (*BinaryToStringWFunc)(const BYTE *pbBinary,
57 DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString);
58
59static BOOL EncodeBinaryToBinaryA(const BYTE *pbBinary,
60 DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
61{
62 BOOL ret = TRUE;
63
64 if (pszString)
65 {
66 if (*pcchString < cbBinary)
67 {
69 ret = FALSE;
70 }
71 else if (cbBinary)
72 memcpy(pszString, pbBinary, cbBinary);
73 }
74 else
75 *pcchString = cbBinary;
76
77 return ret;
78}
79
81{
82 if (ptr + slen > end)
83 slen = end - ptr;
84 memcpy(ptr, s, slen);
85 return slen;
86}
87
88static DWORD encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep,
89 char* out_buf, DWORD *out_len)
90{
91 int div, i;
92 const BYTE *d = in_buf;
93 int bytes = (in_len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
94 LPSTR ptr;
95 LPCSTR end;
96 char chunk[4];
97
98 if (!out_buf)
99 {
100 TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
101 *out_len = bytes + pad_bytes;
102 *out_len += (*out_len / 64 + (*out_len % 64 ? 1 : 0)) * strlen(sep) + 1;
103 return 0;
104 }
105
106 /* Three bytes of input give 4 chars of output */
107 div = in_len / 3;
108
109 ptr = out_buf;
110 end = ptr + *out_len;
111 i = 0;
112 while (div > 0 && ptr < end)
113 {
114 /* first char is the first 6 bits of the first byte*/
115 chunk[0] = b64[ ( d[0] >> 2) & 0x3f ];
116 /* second char is the last 2 bits of the first byte and the first 4
117 * bits of the second byte */
118 chunk[1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
119 /* third char is the last 4 bits of the second byte and the first 2
120 * bits of the third byte */
121 chunk[2] = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)];
122 /* fourth char is the remaining 6 bits of the third byte */
123 chunk[3] = b64[ d[2] & 0x3f];
124 ptr += stradd(ptr, end, chunk, 4);
125 i += 4;
126 d += 3;
127 div--;
128
129 if (i && i % 64 == 0)
130 ptr += stradd(ptr, end, sep, strlen(sep));
131 }
132
133 switch(pad_bytes)
134 {
135 case 1:
136 /* first char is the first 6 bits of the first byte*/
137 chunk[0] = b64[ ( d[0] >> 2) & 0x3f ];
138 /* second char is the last 2 bits of the first byte and the first 4
139 * bits of the second byte */
140 chunk[1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
141 /* third char is the last 4 bits of the second byte padded with
142 * two zeroes */
143 chunk[2] = b64[ ((d[1] << 2) & 0x3c) ];
144 /* fourth char is a = to indicate one byte of padding */
145 chunk[3] = '=';
146 ptr += stradd(ptr, end, chunk, 4);
147 break;
148 case 2:
149 /* first char is the first 6 bits of the first byte*/
150 chunk[0] = b64[ ( d[0] >> 2) & 0x3f ];
151 /* second char is the last 2 bits of the first byte padded with
152 * four zeroes*/
153 chunk[1] = b64[ ((d[0] << 4) & 0x30)];
154 /* third char is = to indicate padding */
155 chunk[2] = '=';
156 /* fourth char is = to indicate padding */
157 chunk[3] = '=';
158 ptr += stradd(ptr, end, chunk, 4);
159 break;
160 }
161 ptr += stradd(ptr, end, sep, strlen(sep));
162
163 return ptr - out_buf;
164}
165
166static BOOL BinaryToBase64A(const BYTE *pbBinary,
167 DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
168{
169 static const char crlf[] = "\r\n", lf[] = "\n";
170 BOOL ret = TRUE;
171 LPCSTR header = NULL, trailer = NULL, sep;
172 DWORD charsNeeded;
173
175 sep = lf;
176 else if (dwFlags & CRYPT_STRING_NOCRLF)
177 sep = "";
178 else
179 sep = crlf;
180 switch (dwFlags & 0x0fffffff)
181 {
183 /* no header or footer */
184 break;
187 trailer = CERT_TRAILER;
188 break;
191 trailer = CERT_REQUEST_TRAILER;
192 break;
195 trailer = X509_TRAILER;
196 break;
197 }
198
199 charsNeeded = 0;
200 encodeBase64A(pbBinary, cbBinary, sep, NULL, &charsNeeded);
201 if (header)
202 charsNeeded += strlen(header) + strlen(sep);
203 if (trailer)
204 charsNeeded += strlen(trailer) + strlen(sep);
205
206 if (pszString)
207 {
208 LPSTR ptr = pszString;
209 DWORD size = *pcchString;
210 LPSTR end = ptr + size;
211
212 if (header)
213 {
215 ptr += stradd(ptr, end, sep, strlen(sep));
216 size = end - ptr;
217 }
218 ptr += encodeBase64A(pbBinary, cbBinary, sep, ptr, &size);
219 if (trailer)
220 {
221 ptr += stradd(ptr, end, trailer, strlen(trailer));
222 ptr += stradd(ptr, end, sep, strlen(sep));
223 }
224
225 if (ptr < end)
226 *ptr = '\0';
227
228 if (charsNeeded <= *pcchString)
229 {
230 *pcchString = charsNeeded - 1;
231 }
232 else
233 {
234 *pcchString = charsNeeded;
236 ret = FALSE;
237 }
238 }
239 else
240 *pcchString = charsNeeded;
241
242 return ret;
243}
244
245static BOOL BinaryToHexRawA(const BYTE *bin, DWORD nbin, DWORD flags, char *str, DWORD *nstr)
246{
247 static const char hex[] = "0123456789abcdef";
248 DWORD needed;
249
251 needed = 0;
252 else if (flags & CRYPT_STRING_NOCR)
253 needed = 1;
254 else
255 needed = 2;
256
257 needed += nbin * 2 + 1;
258
259 if (!str)
260 {
261 *nstr = needed;
262 return TRUE;
263 }
264
265 if (needed > *nstr && *nstr < 3)
266 {
268 return FALSE;
269 }
270
271 nbin = min(nbin, (*nstr - 1) / 2);
272
273 while (nbin--)
274 {
275 *str++ = hex[(*bin >> 4) & 0xf];
276 *str++ = hex[*bin & 0xf];
277 bin++;
278 }
279
280 if (needed > *nstr)
281 {
282 *str = 0;
284 return FALSE;
285 }
286
288 {
289 *str++ = '\n';
290 }
291 else if (!(flags & CRYPT_STRING_NOCRLF))
292 {
293 *str++ = '\r';
294 *str++ = '\n';
295 }
296
297 *str = 0;
298 *nstr = needed - 1;
299 return TRUE;
300}
301
303 DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
304{
306
307 TRACE("(%p, %ld, %08lx, %p, %p)\n", pbBinary, cbBinary, dwFlags, pszString,
308 pcchString);
309
310 if (!pbBinary)
311 {
313 return FALSE;
314 }
315 if (!pcchString)
316 {
318 return FALSE;
319 }
320
321 switch (dwFlags & 0x0fffffff)
322 {
325 break;
331 break;
334 break;
335 case CRYPT_STRING_HEX:
339 FIXME("Unimplemented type %ld\n", dwFlags & 0x0fffffff);
340 /* fall through */
341 default:
343 return FALSE;
344 }
345 return encoder(pbBinary, cbBinary, dwFlags, pszString, pcchString);
346}
347
348static BOOL EncodeBinaryToBinaryW(const BYTE *in_buf, DWORD in_len, DWORD flags, WCHAR *out_buf, DWORD *out_len)
349{
350 BOOL ret = TRUE;
351
352 if (out_buf)
353 {
354 if (*out_len < in_len)
355 {
357 ret = FALSE;
358 }
359 else if (in_len)
360 memcpy(out_buf, in_buf, in_len);
361 }
362 else
363 *out_len = in_len;
364
365 return ret;
366}
367
368static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep,
369 WCHAR* out_buf, DWORD *out_len)
370{
371 int div, i;
372 const BYTE *d = in_buf;
373 int bytes = (in_len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
374 DWORD needed;
375 LPWSTR ptr;
376
377 TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
378 needed = bytes + pad_bytes;
379 needed += (needed / 64 + (needed % 64 ? 1 : 0)) * lstrlenW(sep);
380 needed++;
381
382 if (needed > *out_len)
383 {
384 *out_len = needed;
386 }
387 else
388 *out_len = needed;
389
390 /* Three bytes of input give 4 chars of output */
391 div = in_len / 3;
392
393 ptr = out_buf;
394 i = 0;
395 while (div > 0)
396 {
397 /* first char is the first 6 bits of the first byte*/
398 *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
399 /* second char is the last 2 bits of the first byte and the first 4
400 * bits of the second byte */
401 *ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
402 /* third char is the last 4 bits of the second byte and the first 2
403 * bits of the third byte */
404 *ptr++ = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)];
405 /* fourth char is the remaining 6 bits of the third byte */
406 *ptr++ = b64[ d[2] & 0x3f];
407 i += 4;
408 d += 3;
409 div--;
410
411 if (i && i % 64 == 0)
412 {
413 lstrcpyW(ptr, sep);
414 ptr += lstrlenW(sep);
415 }
416 }
417
418 switch(pad_bytes)
419 {
420 case 1:
421 /* first char is the first 6 bits of the first byte*/
422 *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
423 /* second char is the last 2 bits of the first byte and the first 4
424 * bits of the second byte */
425 *ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
426 /* third char is the last 4 bits of the second byte padded with
427 * two zeroes */
428 *ptr++ = b64[ ((d[1] << 2) & 0x3c) ];
429 /* fourth char is a = to indicate one byte of padding */
430 *ptr++ = '=';
431 break;
432 case 2:
433 /* first char is the first 6 bits of the first byte*/
434 *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
435 /* second char is the last 2 bits of the first byte padded with
436 * four zeroes*/
437 *ptr++ = b64[ ((d[0] << 4) & 0x30)];
438 /* third char is = to indicate padding */
439 *ptr++ = '=';
440 /* fourth char is = to indicate padding */
441 *ptr++ = '=';
442 break;
443 }
444 lstrcpyW(ptr, sep);
445
446 return ERROR_SUCCESS;
447}
448
449static BOOL BinaryToBase64W(const BYTE *pbBinary,
450 DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
451{
452 BOOL ret = TRUE;
453 LPCWSTR header = NULL, trailer = NULL, sep;
454 DWORD charsNeeded;
455
457 sep = L"\n";
458 else if (dwFlags & CRYPT_STRING_NOCRLF)
459 sep = L"";
460 else
461 sep = L"\r\n";
462 switch (dwFlags & 0x0fffffff)
463 {
465 /* no header or footer */
466 break;
469 trailer = CERT_TRAILER_W;
470 break;
473 trailer = CERT_REQUEST_TRAILER_W;
474 break;
477 trailer = X509_TRAILER_W;
478 break;
479 }
480
481 charsNeeded = 0;
482 encodeBase64W(pbBinary, cbBinary, sep, NULL, &charsNeeded);
483 if (header)
484 charsNeeded += lstrlenW(header) + lstrlenW(sep);
485 if (trailer)
486 charsNeeded += lstrlenW(trailer) + lstrlenW(sep);
487
488 if (pszString)
489 {
490 if (charsNeeded <= *pcchString)
491 {
492 LPWSTR ptr = pszString;
493 DWORD size = charsNeeded;
494
495 if (header)
496 {
498 ptr += lstrlenW(ptr);
499 lstrcpyW(ptr, sep);
500 ptr += lstrlenW(sep);
501 }
502 encodeBase64W(pbBinary, cbBinary, sep, ptr, &size);
503 ptr += size - 1;
504 if (trailer)
505 {
506 lstrcpyW(ptr, trailer);
507 ptr += lstrlenW(ptr);
508 lstrcpyW(ptr, sep);
509 }
510 *pcchString = charsNeeded - 1;
511 }
512 else
513 {
514 *pcchString = charsNeeded;
516 ret = FALSE;
517 }
518 }
519 else
520 *pcchString = charsNeeded;
521
522 return ret;
523}
524
526{
527 static const WCHAR hex[] = L"0123456789abcdef";
528 DWORD needed;
529
531 needed = 0;
532 else if (flags & CRYPT_STRING_NOCR)
533 needed = 1;
534 else
535 needed = 2;
536
537 needed += nbin * 2 + 1;
538
539 if (!str)
540 {
541 *nstr = needed;
542 return TRUE;
543 }
544
545 if (needed > *nstr)
546 {
548 return FALSE;
549 }
550
551 while (nbin--)
552 {
553 *str++ = hex[(*bin >> 4) & 0xf];
554 *str++ = hex[*bin & 0xf];
555 bin++;
556 }
557
559 *str++ = '\n';
560 else if (!(flags & CRYPT_STRING_NOCRLF))
561 {
562 *str++ = '\r';
563 *str++ = '\n';
564 }
565
566 *str = 0;
567 *nstr = needed - 1;
568 return TRUE;
569}
570
571static BOOL binary_to_hexW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, DWORD *nstr)
572{
573 static const WCHAR hex[] = L"0123456789abcdef";
574 DWORD needed, i;
575
576 needed = nbin * 3; /* spaces + terminating \0 */
577
579 {
580 needed += (nbin + 7) / 16; /* space every 16 characters */
581 needed += 1; /* terminating \n */
582 }
583 else if (!(flags & CRYPT_STRING_NOCRLF))
584 {
585 needed += (nbin + 7) / 16; /* space every 16 characters */
586 needed += nbin / 16 + 1; /* LF every 16 characters + terminating \r */
587
588 if (nbin % 16)
589 needed += 1; /* terminating \n */
590 }
591
592 if (!str)
593 {
594 *nstr = needed;
595 return TRUE;
596 }
597
598 if (needed > *nstr)
599 {
601 return FALSE;
602 }
603
604 for (i = 0; i < nbin; i++)
605 {
606 *str++ = hex[(bin[i] >> 4) & 0xf];
607 *str++ = hex[bin[i] & 0xf];
608
609 if (i >= nbin - 1) break;
610
611 if (i && !(flags & CRYPT_STRING_NOCRLF))
612 {
613 if (!((i + 1) % 16))
614 {
616 *str++ = '\n';
617 else
618 {
619 *str++ = '\r';
620 *str++ = '\n';
621 }
622 continue;
623 }
624 else if (!((i + 1) % 8))
625 *str++ = ' ';
626 }
627
628 *str++ = ' ';
629 }
630
632 *str++ = '\n';
633 else if (!(flags & CRYPT_STRING_NOCRLF))
634 {
635 *str++ = '\r';
636 *str++ = '\n';
637 }
638
639 *str = 0;
640 *nstr = needed - 1;
641 return TRUE;
642}
643
645 DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
646{
648
649 TRACE("(%p, %ld, %08lx, %p, %p)\n", pbBinary, cbBinary, dwFlags, pszString,
650 pcchString);
651
652 if (!pbBinary)
653 {
655 return FALSE;
656 }
657 if (!pcchString)
658 {
660 return FALSE;
661 }
662
663 switch (dwFlags & 0x0fffffff)
664 {
667 break;
673 break;
676 break;
677 case CRYPT_STRING_HEX:
679 break;
683 FIXME("Unimplemented type %ld\n", dwFlags & 0x0fffffff);
684 /* fall through */
685 default:
687 return FALSE;
688 }
689 return encoder(pbBinary, cbBinary, dwFlags, pszString, pcchString);
690}
691
692#define BASE64_DECODE_PADDING 0x100
693#define BASE64_DECODE_WHITESPACE 0x200
694#define BASE64_DECODE_INVALID 0x300
695
696static inline int decodeBase64Byte(int c)
697{
699
700 if (c >= 'A' && c <= 'Z')
701 ret = c - 'A';
702 else if (c >= 'a' && c <= 'z')
703 ret = c - 'a' + 26;
704 else if (c >= '0' && c <= '9')
705 ret = c - '0' + 52;
706 else if (c == '+')
707 ret = 62;
708 else if (c == '/')
709 ret = 63;
710 else if (c == '=')
712 else if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
714 return ret;
715}
716
717/* Unlike CryptStringToBinaryA, cchString is guaranteed to be the length of the
718 * string to convert.
719 */
720typedef LONG (*StringToBinaryAFunc)(LPCSTR pszString, DWORD cchString,
721 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags);
722
723static LONG Base64ToBinary(const void* pszString, BOOL wide, DWORD cchString,
724 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
725{
726 DWORD cbIn, cbValid, cbOut, hasPadding;
727 BYTE block[4];
728 for (cbIn = cbValid = cbOut = hasPadding = 0; cbIn < cchString; ++cbIn)
729 {
730 int c = wide ? (int)((WCHAR*)pszString)[cbIn] : (int)((char*)pszString)[cbIn];
731 int d = decodeBase64Byte(c);
733 goto invalid;
735 continue;
736
737 /* When padding starts, data is not acceptable */
738 if (hasPadding && d != BASE64_DECODE_PADDING)
739 goto invalid;
740
741 /* Padding after a full block (like "VVVV=") is ok and stops decoding */
742 if (d == BASE64_DECODE_PADDING && (cbValid & 3) == 0)
743 break;
744
745 cbValid += 1;
746
748 {
749 hasPadding = 1;
750 /* When padding reaches a full block, stop decoding */
751 if ((cbValid & 3) == 0)
752 break;
753 continue;
754 }
755
756 /* cbOut is incremented in the 4-char block as follows: "1-23" */
757 if ((cbValid & 3) != 2)
758 cbOut += 1;
759 }
760 /* Fail if the block has bad padding; omitting padding is fine */
761 if ((cbValid & 3) != 0 && hasPadding)
762 goto invalid;
763 /* Check available buffer size */
764 if (pbBinary && *pcbBinary && cbOut > *pcbBinary)
765 goto overflow;
766 /* Convert the data; this step depends on the validity checks above! */
767 if (pbBinary) for (cbIn = cbValid = cbOut = 0; cbIn < cchString; ++cbIn)
768 {
769 int c = wide ? (int)((WCHAR*)pszString)[cbIn] : (int)((char*)pszString)[cbIn];
770 int d = decodeBase64Byte(c);
772 continue;
774 break;
775 block[cbValid & 3] = d;
776 cbValid += 1;
777 switch (cbValid & 3) {
778 case 1:
779 pbBinary[cbOut++] = (block[0] << 2);
780 break;
781 case 2:
782 pbBinary[cbOut-1] = (block[0] << 2) | (block[1] >> 4);
783 break;
784 case 3:
785 pbBinary[cbOut++] = (block[1] << 4) | (block[2] >> 2);
786 break;
787 case 0:
788 pbBinary[cbOut++] = (block[2] << 6) | (block[3] >> 0);
789 break;
790 }
791 }
792 *pcbBinary = cbOut;
793 if (pdwSkip)
794 *pdwSkip = 0;
795 if (pdwFlags)
796 *pdwFlags = CRYPT_STRING_BASE64;
797 return ERROR_SUCCESS;
798overflow:
800invalid:
801 *pcbBinary = cbOut;
802 return ERROR_INVALID_DATA;
803}
804
805static LONG Base64ToBinaryA(LPCSTR pszString, DWORD cchString,
806 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
807{
808 return Base64ToBinary(pszString, FALSE, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
809}
810
812 DWORD cchString, BYTE *pbBinary,
813 DWORD *pcbBinary, DWORD *pdwSkip)
814{
815 LONG ret;
817 LPCSTR trailer = CERT_TRAILER_START;
818
819 LPCSTR headerBegins;
820 LPCSTR dataBegins;
821 LPCSTR trailerBegins;
822 size_t dataLength;
823
824 if ((strlen(header) + strlen(trailer)) > cchString)
825 {
826 return ERROR_INVALID_DATA;
827 }
828
829 if (!(headerBegins = strstr(pszString, header)))
830 {
831 TRACE("Can't find %s in %s.\n", header, debugstr_an(pszString, cchString));
832 return ERROR_INVALID_DATA;
833 }
834
835 dataBegins = headerBegins + strlen(header);
836 if (!(dataBegins = strstr(dataBegins, CERT_DELIMITER)))
837 {
838 return ERROR_INVALID_DATA;
839 }
840 dataBegins += strlen(CERT_DELIMITER);
841 if (*dataBegins == '\r') dataBegins++;
842 if (*dataBegins == '\n') dataBegins++;
843
844 if (!(trailerBegins = strstr(dataBegins, trailer)))
845 {
846 return ERROR_INVALID_DATA;
847 }
848 if (*(trailerBegins-1) == '\n') trailerBegins--;
849 if (*(trailerBegins-1) == '\r') trailerBegins--;
850
851 if (pdwSkip)
852 *pdwSkip = headerBegins - pszString;
853
854 dataLength = trailerBegins - dataBegins;
855
856 ret = Base64ToBinaryA(dataBegins, dataLength, pbBinary, pcbBinary, NULL,
857 NULL);
858
859 return ret;
860}
861
862static LONG Base64HeaderToBinaryA(LPCSTR pszString, DWORD cchString,
863 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
864{
865 LONG ret = Base64WithHeaderAndTrailerToBinaryA(pszString, cchString,
866 pbBinary, pcbBinary, pdwSkip);
867
868 if (!ret && pdwFlags)
869 *pdwFlags = CRYPT_STRING_BASE64HEADER;
870 return ret;
871}
872
873static LONG Base64RequestHeaderToBinaryA(LPCSTR pszString, DWORD cchString,
874 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
875{
876 LONG ret = Base64WithHeaderAndTrailerToBinaryA(pszString, cchString,
877 pbBinary, pcbBinary, pdwSkip);
878
879 if (!ret && pdwFlags)
881 return ret;
882}
883
884static LONG Base64X509HeaderToBinaryA(LPCSTR pszString, DWORD cchString,
885 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
886{
887 LONG ret = Base64WithHeaderAndTrailerToBinaryA(pszString, cchString,
888 pbBinary, pcbBinary, pdwSkip);
889
890 if (!ret && pdwFlags)
892 return ret;
893}
894
895static LONG Base64AnyToBinaryA(LPCSTR pszString, DWORD cchString,
896 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
897{
898 LONG ret;
899
900 ret = Base64HeaderToBinaryA(pszString, cchString, pbBinary, pcbBinary,
901 pdwSkip, pdwFlags);
902 if (ret == ERROR_INVALID_DATA)
903 ret = Base64ToBinaryA(pszString, cchString, pbBinary, pcbBinary,
904 pdwSkip, pdwFlags);
905 return ret;
906}
907
908static LONG DecodeBinaryToBinaryA(LPCSTR pszString, DWORD cchString,
909 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
910{
912
913 if (*pcbBinary < cchString)
914 {
915 if (!pbBinary)
916 *pcbBinary = cchString;
917 else
918 {
920 *pcbBinary = cchString;
921 }
922 }
923 else
924 {
925 if (cchString)
926 memcpy(pbBinary, pszString, cchString);
927 *pcbBinary = cchString;
928 }
929 return ret;
930}
931
932static LONG DecodeAnyA(LPCSTR pszString, DWORD cchString,
933 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
934{
935 LONG ret;
936
937 ret = Base64HeaderToBinaryA(pszString, cchString, pbBinary, pcbBinary,
938 pdwSkip, pdwFlags);
939 if (ret == ERROR_INVALID_DATA)
940 ret = Base64ToBinaryA(pszString, cchString, pbBinary, pcbBinary,
941 pdwSkip, pdwFlags);
942 if (ret == ERROR_INVALID_DATA)
943 ret = DecodeBinaryToBinaryA(pszString, cchString, pbBinary, pcbBinary,
944 pdwSkip, pdwFlags);
945 return ret;
946}
947
949{
950 switch (c)
951 {
952 case '-':
953 case ',':
954 case ' ':
955 case '\t':
956 case '\r':
957 case '\n':
958 return TRUE;
959
960 default:
961 return FALSE;
962 }
963}
964
965static WCHAR wchar_from_str(BOOL wide, const void **str, DWORD *len)
966{
967 WCHAR c;
968
969 if (!*len)
970 return 0;
971
972 --*len;
973 if (wide)
974 c = *(*(const WCHAR **)str)++;
975 else
976 c = *(*(const char **)str)++;
977
978 return c ? c : 0xffff;
979}
980
982{
983 if (c >= '0' && c <= '9')
984 return c - '0';
985 c = towlower(c);
986 if (c >= 'a' && c <= 'f')
987 return c - 'a' + 0xa;
988 return 0xff;
989}
990
991static LONG string_to_hex(const void* str, BOOL wide, DWORD len, BYTE *hex, DWORD *hex_len,
992 DWORD *skipped, DWORD *ret_flags)
993{
994 unsigned int byte_idx = 0;
995 BYTE d1, d2;
996 WCHAR c;
997
998 if (!str || !hex_len)
1000
1001 if (!len)
1002 len = wide ? wcslen(str) : strlen(str);
1003
1004 if (wide && !len)
1006
1007 if (skipped)
1008 *skipped = 0;
1009 if (ret_flags)
1010 *ret_flags = 0;
1011
1012 while ((c = wchar_from_str(wide, &str, &len)) && is_hex_string_special_char(c))
1013 ;
1014
1015 while ((d1 = digit_from_char(c)) != 0xff)
1016 {
1017 if ((d2 = digit_from_char(wchar_from_str(wide, &str, &len))) == 0xff)
1018 {
1019 if (!hex)
1020 *hex_len = 0;
1021 return ERROR_INVALID_DATA;
1022 }
1023
1024 if (hex && byte_idx < *hex_len)
1025 hex[byte_idx] = (d1 << 4) | d2;
1026
1027 ++byte_idx;
1028
1029 do
1030 {
1031 c = wchar_from_str(wide, &str, &len);
1032 } while (c == '-' || c == ',');
1033 }
1034
1035 while (c)
1036 {
1038 {
1039 if (!hex)
1040 *hex_len = 0;
1041 return ERROR_INVALID_DATA;
1042 }
1043 c = wchar_from_str(wide, &str, &len);
1044 }
1045
1046 if (hex && byte_idx > *hex_len)
1047 return ERROR_MORE_DATA;
1048
1049 if (ret_flags)
1050 *ret_flags = CRYPT_STRING_HEX;
1051
1052 *hex_len = byte_idx;
1053
1054 return ERROR_SUCCESS;
1055}
1056
1057static LONG string_to_hexA(const char *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
1058{
1059 return string_to_hex(str, FALSE, len, hex, hex_len, skipped, ret_flags);
1060}
1061
1063 DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary,
1064 DWORD *pdwSkip, DWORD *pdwFlags)
1065{
1067 LONG ret;
1068
1069 TRACE("(%s, %ld, %08lx, %p, %p, %p, %p)\n", debugstr_an(pszString, cchString ? cchString : -1),
1070 cchString, dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1071
1072 if (!pszString)
1073 {
1075 return FALSE;
1076 }
1077 /* Only the bottom byte contains valid types */
1078 if (dwFlags & 0xfffffff0)
1079 {
1081 return FALSE;
1082 }
1083 switch (dwFlags)
1084 {
1087 break;
1090 break;
1093 break;
1096 break;
1099 break;
1102 break;
1103 case CRYPT_STRING_ANY:
1105 break;
1106 case CRYPT_STRING_HEX:
1108 break;
1112 FIXME("Unimplemented type %ld\n", dwFlags & 0x7fffffff);
1113 /* fall through */
1114 default:
1116 return FALSE;
1117 }
1118 if (!cchString)
1119 cchString = strlen(pszString);
1120 ret = decoder(pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1121 if (ret)
1123 return ret == ERROR_SUCCESS;
1124}
1125
1126/* Unlike CryptStringToBinaryW, cchString is guaranteed to be the length of the
1127 * string to convert.
1128 */
1129typedef LONG (*StringToBinaryWFunc)(LPCWSTR pszString, DWORD cchString,
1130 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags);
1131
1132static LONG Base64ToBinaryW(LPCWSTR pszString, DWORD cchString,
1133 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1134{
1135 return Base64ToBinary(pszString, TRUE, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1136}
1137
1139 DWORD cchString, BYTE *pbBinary,
1140 DWORD *pcbBinary, DWORD *pdwSkip)
1141{
1142 LONG ret;
1144 LPCWSTR trailer = CERT_TRAILER_START_W;
1145
1146 LPCWSTR headerBegins;
1147 LPCWSTR dataBegins;
1148 LPCWSTR trailerBegins;
1149 size_t dataLength;
1150
1151 if ((lstrlenW(header) + lstrlenW(trailer)) > cchString)
1152 {
1153 return ERROR_INVALID_DATA;
1154 }
1155
1156 if (!(headerBegins = wcsstr(pszString, header)))
1157 {
1158 TRACE("Can't find %s in %s.\n", debugstr_w(header), debugstr_wn(pszString, cchString));
1159 return ERROR_INVALID_DATA;
1160 }
1161
1162 dataBegins = headerBegins + lstrlenW(header);
1163 if (!(dataBegins = wcsstr(dataBegins, CERT_DELIMITER_W)))
1164 {
1165 return ERROR_INVALID_DATA;
1166 }
1167 dataBegins += lstrlenW(CERT_DELIMITER_W);
1168 if (*dataBegins == '\r') dataBegins++;
1169 if (*dataBegins == '\n') dataBegins++;
1170
1171 if (!(trailerBegins = wcsstr(dataBegins, trailer)))
1172 {
1173 return ERROR_INVALID_DATA;
1174 }
1175 if (*(trailerBegins-1) == '\n') trailerBegins--;
1176 if (*(trailerBegins-1) == '\r') trailerBegins--;
1177
1178 if (pdwSkip)
1179 *pdwSkip = headerBegins - pszString;
1180
1181 dataLength = trailerBegins - dataBegins;
1182
1183 ret = Base64ToBinaryW(dataBegins, dataLength, pbBinary, pcbBinary, NULL,
1184 NULL);
1185
1186 return ret;
1187}
1188
1189static LONG Base64HeaderToBinaryW(LPCWSTR pszString, DWORD cchString,
1190 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1191{
1192 LONG ret = Base64WithHeaderAndTrailerToBinaryW(pszString, cchString,
1193 pbBinary, pcbBinary, pdwSkip);
1194
1195 if (!ret && pdwFlags)
1196 *pdwFlags = CRYPT_STRING_BASE64HEADER;
1197 return ret;
1198}
1199
1201 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1202{
1203 LONG ret = Base64WithHeaderAndTrailerToBinaryW(pszString, cchString,
1204 pbBinary, pcbBinary, pdwSkip);
1205
1206 if (!ret && pdwFlags)
1208 return ret;
1209}
1210
1211static LONG Base64X509HeaderToBinaryW(LPCWSTR pszString, DWORD cchString,
1212 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1213{
1214 LONG ret = Base64WithHeaderAndTrailerToBinaryW(pszString, cchString,
1215 pbBinary, pcbBinary, pdwSkip);
1216
1217 if (!ret && pdwFlags)
1219 return ret;
1220}
1221
1222static LONG Base64AnyToBinaryW(LPCWSTR pszString, DWORD cchString,
1223 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1224{
1225 LONG ret;
1226
1227 ret = Base64HeaderToBinaryW(pszString, cchString, pbBinary, pcbBinary,
1228 pdwSkip, pdwFlags);
1229 if (ret == ERROR_INVALID_DATA)
1230 ret = Base64ToBinaryW(pszString, cchString, pbBinary, pcbBinary,
1231 pdwSkip, pdwFlags);
1232 return ret;
1233}
1234
1235static LONG DecodeBinaryToBinaryW(LPCWSTR pszString, DWORD cchString,
1236 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1237{
1239
1240 if (*pcbBinary < cchString)
1241 {
1242 if (!pbBinary)
1243 *pcbBinary = cchString;
1244 else
1245 {
1247 *pcbBinary = cchString;
1248 }
1249 }
1250 else
1251 {
1252 if (cchString)
1253 memcpy(pbBinary, pszString, cchString * sizeof(WCHAR));
1254 *pcbBinary = cchString * sizeof(WCHAR);
1255 }
1256 return ret;
1257}
1258
1259static LONG DecodeAnyW(LPCWSTR pszString, DWORD cchString,
1260 BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
1261{
1262 LONG ret;
1263
1264 ret = Base64HeaderToBinaryW(pszString, cchString, pbBinary, pcbBinary,
1265 pdwSkip, pdwFlags);
1266 if (ret == ERROR_INVALID_DATA)
1267 ret = Base64ToBinaryW(pszString, cchString, pbBinary, pcbBinary,
1268 pdwSkip, pdwFlags);
1269 if (ret == ERROR_INVALID_DATA)
1270 ret = DecodeBinaryToBinaryW(pszString, cchString, pbBinary, pcbBinary,
1271 pdwSkip, pdwFlags);
1272 return ret;
1273}
1274
1275static LONG string_to_hexW(const WCHAR *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
1276{
1277 return string_to_hex(str, TRUE, len, hex, hex_len, skipped, ret_flags);
1278}
1279
1281 DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary,
1282 DWORD *pdwSkip, DWORD *pdwFlags)
1283{
1285 LONG ret;
1286
1287 TRACE("(%s, %ld, %08lx, %p, %p, %p, %p)\n", debugstr_wn(pszString, cchString ? cchString : -1),
1288 cchString, dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1289
1290 if (!pszString)
1291 {
1293 return FALSE;
1294 }
1295 /* Only the bottom byte contains valid types */
1296 if (dwFlags & 0xfffffff0)
1297 {
1299 return FALSE;
1300 }
1301 switch (dwFlags)
1302 {
1305 break;
1308 break;
1311 break;
1314 break;
1317 break;
1320 break;
1321 case CRYPT_STRING_ANY:
1323 break;
1324 case CRYPT_STRING_HEX:
1326 break;
1330 FIXME("Unimplemented type %ld\n", dwFlags & 0x7fffffff);
1331 /* fall through */
1332 default:
1334 return FALSE;
1335 }
1336 if (!cchString)
1337 cchString = lstrlenW(pszString);
1338 ret = decoder(pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1339 if (ret)
1341 return ret == ERROR_SUCCESS;
1342}
ios_base &_STLP_CALL hex(ios_base &__s)
Definition: _ios_base.h:324
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR CERT_REQUEST_TRAILER_W[]
Definition: base64.c:47
static const WCHAR CERT_TRAILER_W[]
Definition: base64.c:44
static LONG string_to_hexW(const WCHAR *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
Definition: base64.c:1275
BOOL WINAPI CryptBinaryToStringW(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
Definition: base64.c:644
static LONG Base64HeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1189
static BOOL BinaryToHexRawW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, DWORD *nstr)
Definition: base64.c:525
static LONG Base64RequestHeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:873
#define CERT_HEADER_START
Definition: base64.c:32
static const WCHAR CERT_DELIMITER_W[]
Definition: base64.c:43
LONG(* StringToBinaryWFunc)(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1129
BOOL WINAPI CryptStringToBinaryW(LPCWSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1280
static LONG Base64HeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:862
LONG(* StringToBinaryAFunc)(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:720
static LONG Base64ToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:805
static BOOL EncodeBinaryToBinaryW(const BYTE *in_buf, DWORD in_len, DWORD flags, WCHAR *out_buf, DWORD *out_len)
Definition: base64.c:348
#define X509_TRAILER
Definition: base64.c:39
static LONG string_to_hexA(const char *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
Definition: base64.c:1057
static DWORD stradd(LPSTR ptr, LPCSTR end, LPCSTR s, DWORD slen)
Definition: base64.c:80
#define BASE64_DECODE_PADDING
Definition: base64.c:692
static const WCHAR CERT_HEADER_W[]
Definition: base64.c:41
static LONG Base64WithHeaderAndTrailerToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip)
Definition: base64.c:1138
BOOL WINAPI CryptStringToBinaryA(LPCSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1062
static LONG Base64AnyToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:895
#define CERT_TRAILER_START
Definition: base64.c:35
static LONG Base64RequestHeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1200
static LONG DecodeAnyA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:932
static LONG Base64AnyToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1222
static LONG Base64X509HeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1211
static LONG Base64ToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1132
static BOOL binary_to_hexW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, DWORD *nstr)
Definition: base64.c:571
#define CERT_TRAILER
Definition: base64.c:34
static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep, WCHAR *out_buf, DWORD *out_len)
Definition: base64.c:368
BOOL(* BinaryToStringAFunc)(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
Definition: base64.c:54
static BOOL is_hex_string_special_char(WCHAR c)
Definition: base64.c:948
static LONG DecodeBinaryToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1235
static BOOL EncodeBinaryToBinaryA(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
Definition: base64.c:59
static int decodeBase64Byte(int c)
Definition: base64.c:696
static LONG Base64ToBinary(const void *pszString, BOOL wide, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:723
static const WCHAR X509_HEADER_W[]
Definition: base64.c:48
static const WCHAR X509_TRAILER_W[]
Definition: base64.c:49
static BOOL BinaryToHexRawA(const BYTE *bin, DWORD nbin, DWORD flags, char *str, DWORD *nstr)
Definition: base64.c:245
static LONG Base64X509HeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:884
#define BASE64_DECODE_WHITESPACE
Definition: base64.c:693
static DWORD encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep, char *out_buf, DWORD *out_len)
Definition: base64.c:88
#define CERT_REQUEST_HEADER
Definition: base64.c:36
static BOOL BinaryToBase64W(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
Definition: base64.c:449
static BYTE digit_from_char(WCHAR c)
Definition: base64.c:981
static LONG Base64WithHeaderAndTrailerToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip)
Definition: base64.c:811
#define X509_HEADER
Definition: base64.c:38
static const char b64[]
Definition: base64.c:51
#define BASE64_DECODE_INVALID
Definition: base64.c:694
static LONG DecodeAnyW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:1259
BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
Definition: base64.c:302
static LONG DecodeBinaryToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
Definition: base64.c:908
static LONG string_to_hex(const void *str, BOOL wide, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
Definition: base64.c:991
static const WCHAR CERT_TRAILER_START_W[]
Definition: base64.c:45
static const WCHAR CERT_REQUEST_HEADER_W[]
Definition: base64.c:46
#define CERT_DELIMITER
Definition: base64.c:33
static const WCHAR CERT_HEADER_START_W[]
Definition: base64.c:42
static WCHAR wchar_from_str(BOOL wide, const void **str, DWORD *len)
Definition: base64.c:965
#define CERT_HEADER
Definition: base64.c:31
static BOOL BinaryToBase64A(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
Definition: base64.c:166
BOOL(* BinaryToStringWFunc)(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
Definition: base64.c:56
#define CERT_REQUEST_TRAILER
Definition: base64.c:37
static const WCHAR crlf[]
Definition: object.c:1094
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
Definition: wcs.c:2998
_ACRTIMP div_t __cdecl div(int, int)
Definition: math.c:2081
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define d
Definition: ke_i.h:81
#define c
Definition: ke_i.h:80
#define debugstr_wn
Definition: kernel32.h:33
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static struct _PeImage bin
#define min(a, b)
Definition: monoChain.cc:55
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define BOOL
Definition: nt_native.h:43
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
const WCHAR * str
ULONG dataLength
Definition: scsi.h:3797
#define towlower(c)
Definition: wctype.h:97
#define TRACE(s)
Definition: solgame.cpp:4
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
char * LPSTR
Definition: typedefs.h:51
#define CRYPT_STRING_BINARY
Definition: wincrypt.h:3133
#define CRYPT_STRING_BASE64X509CRLHEADER
Definition: wincrypt.h:3140
#define CRYPT_STRING_HEXADDR
Definition: wincrypt.h:3141
#define CRYPT_STRING_BASE64REQUESTHEADER
Definition: wincrypt.h:3134
#define CRYPT_STRING_BASE64HEADER
Definition: wincrypt.h:3131
#define CRYPT_STRING_HEX
Definition: wincrypt.h:3135
#define CRYPT_STRING_BASE64
Definition: wincrypt.h:3132
#define CRYPT_STRING_BASE64_ANY
Definition: wincrypt.h:3137
#define CRYPT_STRING_HEXASCII
Definition: wincrypt.h:3136
#define CRYPT_STRING_HEXRAW
Definition: wincrypt.h:3143
#define CRYPT_STRING_NOCRLF
Definition: wincrypt.h:3149
#define CRYPT_STRING_ANY
Definition: wincrypt.h:3138
#define CRYPT_STRING_NOCR
Definition: wincrypt.h:3150
#define CRYPT_STRING_HEXASCIIADDR
Definition: wincrypt.h:3142
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_DATA
Definition: winerror.h:238
static unsigned int block
Definition: xmlmemory.c:101
unsigned char BYTE
Definition: xxhash.c:193