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-----"
51static const char b64[] =
52"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
66 if (*pcchString < cbBinary)
72 memcpy(pszString, pbBinary, cbBinary);
75 *pcchString = cbBinary;
89 char* out_buf,
DWORD *out_len)
92 const BYTE *
d = in_buf;
93 int bytes = (in_len*8 + 5)/6, pad_bytes = (
bytes % 4) ? 4 - (
bytes % 4) : 0;
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;
118 chunk[1] =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
121 chunk[2] =
b64[ ((
d[1] << 2) & 0x3c) | (
d[2] >> 6 & 0x03)];
129 if (
i &&
i % 64 == 0)
140 chunk[1] =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
163 return ptr - out_buf;
169 static const char crlf[] =
"\r\n", lf[] =
"\n";
228 if (charsNeeded <= *pcchString)
230 *pcchString = charsNeeded - 1;
234 *pcchString = charsNeeded;
240 *pcchString = charsNeeded;
247 static const char hex[] =
"0123456789abcdef";
257 needed += nbin * 2 + 1;
265 if (needed > *nstr && *nstr < 3)
271 nbin =
min(nbin, (*nstr - 1) / 2);
307 TRACE(
"(%p, %ld, %08lx, %p, %p)\n", pbBinary, cbBinary,
dwFlags, pszString,
339 FIXME(
"Unimplemented type %ld\n",
dwFlags & 0x0fffffff);
345 return encoder(pbBinary, cbBinary,
dwFlags, pszString, pcchString);
354 if (*out_len < in_len)
360 memcpy(out_buf, in_buf, in_len);
372 const BYTE *
d = in_buf;
373 int bytes = (in_len*8 + 5)/6, pad_bytes = (
bytes % 4) ? 4 - (
bytes % 4) : 0;
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);
382 if (needed > *out_len)
398 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
401 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
404 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) | (
d[2] >> 6 & 0x03)];
411 if (
i &&
i % 64 == 0)
422 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
425 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
428 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) ];
434 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
437 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30)];
490 if (charsNeeded <= *pcchString)
510 *pcchString = charsNeeded - 1;
514 *pcchString = charsNeeded;
520 *pcchString = charsNeeded;
527 static const WCHAR hex[] =
L"0123456789abcdef";
537 needed += nbin * 2 + 1;
573 static const WCHAR hex[] =
L"0123456789abcdef";
580 needed += (nbin + 7) / 16;
585 needed += (nbin + 7) / 16;
586 needed += nbin / 16 + 1;
604 for (
i = 0;
i < nbin;
i++)
609 if (
i >= nbin - 1)
break;
624 else if (!((
i + 1) % 8))
649 TRACE(
"(%p, %ld, %08lx, %p, %p)\n", pbBinary, cbBinary,
dwFlags, pszString,
683 FIXME(
"Unimplemented type %ld\n",
dwFlags & 0x0fffffff);
689 return encoder(pbBinary, cbBinary,
dwFlags, pszString, pcchString);
692#define BASE64_DECODE_PADDING 0x100
693#define BASE64_DECODE_WHITESPACE 0x200
694#define BASE64_DECODE_INVALID 0x300
700 if (
c >=
'A' &&
c <=
'Z')
702 else if (
c >=
'a' &&
c <=
'z')
704 else if (
c >=
'0' &&
c <=
'9')
712 else if (
c ==
' ' ||
c ==
'\t' ||
c ==
'\r' ||
c ==
'\n')
726 DWORD cbIn, cbValid, cbOut, hasPadding;
728 for (cbIn = cbValid = cbOut = hasPadding = 0; cbIn < cchString; ++cbIn)
730 int c = wide ? (
int)((
WCHAR*)pszString)[cbIn] : (
int)((
char*)pszString)[cbIn];
751 if ((cbValid & 3) == 0)
757 if ((cbValid & 3) != 2)
761 if ((cbValid & 3) != 0 && hasPadding)
764 if (pbBinary && *pcbBinary && cbOut > *pcbBinary)
767 if (pbBinary)
for (cbIn = cbValid = cbOut = 0; cbIn < cchString; ++cbIn)
769 int c = wide ? (
int)((
WCHAR*)pszString)[cbIn] : (
int)((
char*)pszString)[cbIn];
777 switch (cbValid & 3) {
779 pbBinary[cbOut++] = (
block[0] << 2);
782 pbBinary[cbOut-1] = (
block[0] << 2) | (
block[1] >> 4);
785 pbBinary[cbOut++] = (
block[1] << 4) | (
block[2] >> 2);
788 pbBinary[cbOut++] = (
block[2] << 6) | (
block[3] >> 0);
808 return Base64ToBinary(pszString,
FALSE, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
841 if (*dataBegins ==
'\r') dataBegins++;
842 if (*dataBegins ==
'\n') dataBegins++;
844 if (!(trailerBegins =
strstr(dataBegins, trailer)))
848 if (*(trailerBegins-1) ==
'\n') trailerBegins--;
849 if (*(trailerBegins-1) ==
'\r') trailerBegins--;
852 *pdwSkip = headerBegins - pszString;
866 pbBinary, pcbBinary, pdwSkip);
868 if (!
ret && pdwFlags)
877 pbBinary, pcbBinary, pdwSkip);
879 if (!
ret && pdwFlags)
888 pbBinary, pcbBinary, pdwSkip);
890 if (!
ret && pdwFlags)
913 if (*pcbBinary < cchString)
916 *pcbBinary = cchString;
920 *pcbBinary = cchString;
926 memcpy(pbBinary, pszString, cchString);
927 *pcbBinary = cchString;
976 c = *(*(
const char **)
str)++;
978 return c ?
c : 0xffff;
983 if (
c >=
'0' &&
c <=
'9')
986 if (
c >=
'a' &&
c <=
'f')
987 return c -
'a' + 0xa;
994 unsigned int byte_idx = 0;
998 if (!
str || !hex_len)
1024 if (
hex && byte_idx < *hex_len)
1025 hex[byte_idx] = (d1 << 4) | d2;
1032 }
while (
c ==
'-' ||
c ==
',');
1046 if (
hex && byte_idx > *hex_len)
1052 *hex_len = byte_idx;
1069 TRACE(
"(%s, %ld, %08lx, %p, %p, %p, %p)\n",
debugstr_an(pszString, cchString ? cchString : -1),
1070 cchString,
dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1112 FIXME(
"Unimplemented type %ld\n",
dwFlags & 0x7fffffff);
1119 cchString =
strlen(pszString);
1120 ret =
decoder(pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1135 return Base64ToBinary(pszString,
TRUE, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1168 if (*dataBegins ==
'\r') dataBegins++;
1169 if (*dataBegins ==
'\n') dataBegins++;
1171 if (!(trailerBegins =
wcsstr(dataBegins, trailer)))
1175 if (*(trailerBegins-1) ==
'\n') trailerBegins--;
1176 if (*(trailerBegins-1) ==
'\r') trailerBegins--;
1179 *pdwSkip = headerBegins - pszString;
1193 pbBinary, pcbBinary, pdwSkip);
1195 if (!
ret && pdwFlags)
1204 pbBinary, pcbBinary, pdwSkip);
1206 if (!
ret && pdwFlags)
1215 pbBinary, pcbBinary, pdwSkip);
1217 if (!
ret && pdwFlags)
1240 if (*pcbBinary < cchString)
1243 *pcbBinary = cchString;
1247 *pcbBinary = cchString;
1253 memcpy(pbBinary, pszString, cchString *
sizeof(
WCHAR));
1254 *pcbBinary = cchString *
sizeof(
WCHAR);
1287 TRACE(
"(%s, %ld, %08lx, %p, %p, %p, %p)\n",
debugstr_wn(pszString, cchString ? cchString : -1),
1288 cchString,
dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1330 FIXME(
"Unimplemented type %ld\n",
dwFlags & 0x7fffffff);
1338 ret =
decoder(pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
ios_base &_STLP_CALL hex(ios_base &__s)
static unsigned char bytes[4]
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
#define ERROR_INSUFFICIENT_BUFFER
static const WCHAR CERT_REQUEST_TRAILER_W[]
static const WCHAR CERT_TRAILER_W[]
static LONG string_to_hexW(const WCHAR *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
BOOL WINAPI CryptBinaryToStringW(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
static LONG Base64HeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static BOOL BinaryToHexRawW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, DWORD *nstr)
static LONG Base64RequestHeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
#define CERT_HEADER_START
static const WCHAR CERT_DELIMITER_W[]
LONG(* StringToBinaryWFunc)(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
BOOL WINAPI CryptStringToBinaryW(LPCWSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64HeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
LONG(* StringToBinaryAFunc)(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64ToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static BOOL EncodeBinaryToBinaryW(const BYTE *in_buf, DWORD in_len, DWORD flags, WCHAR *out_buf, DWORD *out_len)
static LONG string_to_hexA(const char *str, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
static DWORD stradd(LPSTR ptr, LPCSTR end, LPCSTR s, DWORD slen)
#define BASE64_DECODE_PADDING
static const WCHAR CERT_HEADER_W[]
static LONG Base64WithHeaderAndTrailerToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip)
BOOL WINAPI CryptStringToBinaryA(LPCSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64AnyToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
#define CERT_TRAILER_START
static LONG Base64RequestHeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG DecodeAnyA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64AnyToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64X509HeaderToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG Base64ToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static BOOL binary_to_hexW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, DWORD *nstr)
static LONG encodeBase64W(const BYTE *in_buf, int in_len, LPCWSTR sep, WCHAR *out_buf, DWORD *out_len)
BOOL(* BinaryToStringAFunc)(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
static BOOL is_hex_string_special_char(WCHAR c)
static LONG DecodeBinaryToBinaryW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static BOOL EncodeBinaryToBinaryA(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
static int decodeBase64Byte(int c)
static LONG Base64ToBinary(const void *pszString, BOOL wide, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static const WCHAR X509_HEADER_W[]
static const WCHAR X509_TRAILER_W[]
static BOOL BinaryToHexRawA(const BYTE *bin, DWORD nbin, DWORD flags, char *str, DWORD *nstr)
static LONG Base64X509HeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
#define BASE64_DECODE_WHITESPACE
static DWORD encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep, char *out_buf, DWORD *out_len)
#define CERT_REQUEST_HEADER
static BOOL BinaryToBase64W(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
static BYTE digit_from_char(WCHAR c)
static LONG Base64WithHeaderAndTrailerToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip)
#define BASE64_DECODE_INVALID
static LONG DecodeAnyW(LPCWSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
BOOL WINAPI CryptBinaryToStringA(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
static LONG DecodeBinaryToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
static LONG string_to_hex(const void *str, BOOL wide, DWORD len, BYTE *hex, DWORD *hex_len, DWORD *skipped, DWORD *ret_flags)
static const WCHAR CERT_TRAILER_START_W[]
static const WCHAR CERT_REQUEST_HEADER_W[]
static const WCHAR CERT_HEADER_START_W[]
static WCHAR wchar_from_str(BOOL wide, const void **str, DWORD *len)
static BOOL BinaryToBase64A(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPSTR pszString, DWORD *pcchString)
BOOL(* BinaryToStringWFunc)(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
#define CERT_REQUEST_TRAILER
static const WCHAR crlf[]
#define ERROR_INVALID_PARAMETER
static __inline const char * debugstr_an(const char *s, int n)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
_ACRTIMP wchar_t *__cdecl wcsstr(const wchar_t *, const wchar_t *)
_ACRTIMP div_t __cdecl div(int, int)
_ACRTIMP size_t __cdecl strlen(const char *)
_ACRTIMP char *__cdecl strstr(const char *, const char *)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
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
#define memcpy(s1, s2, n)
static struct _PeImage bin
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
#define CRYPT_STRING_BINARY
#define CRYPT_STRING_BASE64X509CRLHEADER
#define CRYPT_STRING_HEXADDR
#define CRYPT_STRING_BASE64REQUESTHEADER
#define CRYPT_STRING_BASE64HEADER
#define CRYPT_STRING_BASE64
#define CRYPT_STRING_BASE64_ANY
#define CRYPT_STRING_HEXASCII
#define CRYPT_STRING_HEXRAW
#define CRYPT_STRING_NOCRLF
#define CRYPT_STRING_NOCR
#define CRYPT_STRING_HEXASCIIADDR
#define ERROR_INVALID_DATA
static unsigned int block