28#include "wine/unicode.h"
32#define CERT_HEADER "-----BEGIN CERTIFICATE-----"
33#define CERT_HEADER_START "-----BEGIN "
34#define CERT_DELIMITER "-----"
35#define CERT_TRAILER "-----END CERTIFICATE-----"
36#define CERT_TRAILER_START "-----END "
37#define CERT_REQUEST_HEADER "-----BEGIN NEW CERTIFICATE REQUEST-----"
38#define CERT_REQUEST_TRAILER "-----END NEW CERTIFICATE REQUEST-----"
39#define X509_HEADER "-----BEGIN X509 CRL-----"
40#define X509_TRAILER "-----END X509 CRL-----"
43'-',
'-',
'-',
'-',
'-',
'B',
'E',
'G',
'I',
'N',
' ',
'C',
'E',
'R',
'T',
'I',
'F',
'I',
'C',
44'A',
'T',
'E',
'-',
'-',
'-',
'-',
'-',0 };
46'-',
'-',
'-',
'-',
'-',
'B',
'E',
'G',
'I',
'N',
' ',0 };
48'-',
'-',
'-',
'-',
'-',0 };
50'-',
'-',
'-',
'-',
'-',
'E',
'N',
'D',
' ',
'C',
'E',
'R',
'T',
'I',
'F',
'I',
'C',
'A',
'T',
51'E',
'-',
'-',
'-',
'-',
'-',0 };
53'-',
'-',
'-',
'-',
'-',
'E',
'N',
'D',
' ',0 };
55'-',
'-',
'-',
'-',
'-',
'B',
'E',
'G',
'I',
'N',
' ',
'N',
'E',
'W',
' ',
'C',
'E',
'R',
'T',
56'I',
'F',
'I',
'C',
'A',
'T',
'E',
' ',
'R',
'E',
'Q',
'U',
'E',
'S',
'T',
'-',
'-',
'-',
'-',
'-',0 };
58'-',
'-',
'-',
'-',
'-',
'E',
'N',
'D',
' ',
'N',
'E',
'W',
' ',
'C',
'E',
'R',
'T',
'I',
'F',
59'I',
'C',
'A',
'T',
'E',
' ',
'R',
'E',
'Q',
'U',
'E',
'S',
'T',
'-',
'-',
'-',
'-',
'-',0 };
61'-',
'-',
'-',
'-',
'-',
'B',
'E',
'G',
'I',
'N',
' ',
'X',
'5',
'0',
'9',
' ',
'C',
'R',
'L',
62'-',
'-',
'-',
'-',
'-',0 };
64'-',
'-',
'-',
'-',
'-',
'E',
'N',
'D',
' ',
'X',
'5',
'0',
'9',
' ',
'C',
'R',
'L',
'-',
'-',
67static const char b64[] =
68"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
97 char* out_buf,
DWORD *out_len)
100 const BYTE *
d = in_buf;
101 int bytes = (in_len*8 + 5)/6, pad_bytes = (
bytes % 4) ? 4 - (
bytes % 4) : 0;
105 TRACE(
"bytes is %d, pad bytes is %d\n",
bytes, pad_bytes);
106 needed =
bytes + pad_bytes;
107 needed += (needed / 64 + (needed % 64 ? 1 : 0)) *
strlen(sep);
110 if (needed > *out_len)
125 if (
i &&
i % 64 == 0)
131 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
134 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
137 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) | (
d[2] >> 6 & 0x03)];
149 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
152 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
155 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) ];
161 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
164 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30)];
179 static const char crlf[] =
"\r\n", lf[] =
"\n";
302 if (*out_len < in_len)
308 memcpy(out_buf, in_buf, in_len);
320 const BYTE *
d = in_buf;
321 int bytes = (in_len*8 + 5)/6, pad_bytes = (
bytes % 4) ? 4 - (
bytes % 4) : 0;
325 TRACE(
"bytes is %d, pad bytes is %d\n",
bytes, pad_bytes);
326 needed =
bytes + pad_bytes;
327 needed += (needed / 64 + (needed % 64 ? 1 : 0)) *
strlenW(sep);
330 if (needed > *out_len)
345 if (
i &&
i % 64 == 0)
351 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
354 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
357 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) | (
d[2] >> 6 & 0x03)];
369 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
372 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30) | (
d[1] >> 4 & 0x0f)];
375 *
ptr++ =
b64[ ((
d[1] << 2) & 0x3c) ];
381 *
ptr++ =
b64[ (
d[0] >> 2) & 0x3f ];
384 *
ptr++ =
b64[ ((
d[0] << 4) & 0x30)];
399 static const WCHAR crlf[] = {
'\r',
'\n',0 }, lf[] = {
'\n',0 },
empty[] = {0};
516#define BASE64_DECODE_PADDING 0x100
517#define BASE64_DECODE_WHITESPACE 0x200
518#define BASE64_DECODE_INVALID 0x300
524 if (
c >=
'A' &&
c <=
'Z')
526 else if (
c >=
'a' &&
c <=
'z')
528 else if (
c >=
'0' &&
c <=
'9')
536 else if (
c ==
' ' ||
c ==
'\t' ||
c ==
'\r' ||
c ==
'\n')
550 DWORD cbIn, cbValid, cbOut, hasPadding;
552 for (cbIn = cbValid = cbOut = hasPadding = 0; cbIn < cchString; ++cbIn)
575 if ((cbValid & 3) == 0)
581 if ((cbValid & 3) != 2)
585 if ((cbValid & 3) != 0 && hasPadding)
588 if (pbBinary && *pcbBinary && cbOut > *pcbBinary)
591 if (pbBinary)
for (cbIn = cbValid = cbOut = 0; cbIn < cchString; ++cbIn)
601 switch (cbValid & 3) {
603 pbBinary[cbOut++] = (
block[0] << 2);
606 pbBinary[cbOut-1] = (
block[0] << 2) | (
block[1] >> 4);
609 pbBinary[cbOut++] = (
block[1] << 4) | (
block[2] >> 2);
612 pbBinary[cbOut++] = (
block[2] << 6) | (
block[3] >> 0);
665 if (*dataBegins ==
'\r') dataBegins++;
666 if (*dataBegins ==
'\n') dataBegins++;
668 if (!(trailerBegins =
strstr(dataBegins, trailer)))
672 if (*(trailerBegins-1) ==
'\n') trailerBegins--;
673 if (*(trailerBegins-1) ==
'\r') trailerBegins--;
690 pbBinary, pcbBinary, pdwSkip);
692 if (!
ret && pdwFlags)
701 pbBinary, pcbBinary, pdwSkip);
703 if (!
ret && pdwFlags)
712 pbBinary, pcbBinary, pdwSkip);
714 if (!
ret && pdwFlags)
737 if (*pcbBinary < cchString)
740 *pcbBinary = cchString;
744 *pcbBinary = cchString;
751 *pcbBinary = cchString;
780 cchString,
dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
828 ret = decoder(
pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
876 if (*dataBegins ==
'\r') dataBegins++;
877 if (*dataBegins ==
'\n') dataBegins++;
879 if (!(trailerBegins =
strstrW(dataBegins, trailer)))
883 if (*(trailerBegins-1) ==
'\n') trailerBegins--;
884 if (*(trailerBegins-1) ==
'\r') trailerBegins--;
901 pbBinary, pcbBinary, pdwSkip);
903 if (!
ret && pdwFlags)
912 pbBinary, pcbBinary, pdwSkip);
914 if (!
ret && pdwFlags)
923 pbBinary, pcbBinary, pdwSkip);
925 if (!
ret && pdwFlags)
948 if (*pcbBinary < cchString)
951 *pcbBinary = cchString;
955 *pcbBinary = cchString;
962 *pcbBinary = cchString *
sizeof(
WCHAR);
991 cchString,
dwFlags, pbBinary, pcbBinary, pdwSkip, pdwFlags);
1031 FIXME(
"Unimplemented type %d\n",
dwFlags & 0x7fffffff);
1039 ret = decoder(
pszString, cchString, pbBinary, pcbBinary, pdwSkip, pdwFlags);
_STLP_VENDOR_CSTD::ldiv_t div(long __x, long __y)
char * strstr(char *String1, char *String2)
ACPI_SIZE strlen(const char *String)
char * strcpy(char *DstString, const char *SrcString)
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[]
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 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)
static LONG encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep, char *out_buf, DWORD *out_len)
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)
#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 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 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 LONG Base64X509HeaderToBinaryA(LPCSTR pszString, DWORD cchString, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags)
#define BASE64_DECODE_WHITESPACE
#define CERT_REQUEST_HEADER
static BOOL BinaryToBase64W(const BYTE *pbBinary, DWORD cbBinary, DWORD dwFlags, LPWSTR pszString, DWORD *pcchString)
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 const WCHAR CERT_TRAILER_START_W[]
static const WCHAR CERT_REQUEST_HEADER_W[]
static const WCHAR CERT_HEADER_START_W[]
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[]
static const WCHAR empty[]
#define ERROR_INVALID_PARAMETER
static __inline const char * debugstr_an(const char *s, int n)
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 const WCHAR invalid[]
#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
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
#define CRYPT_STRING_HEXASCII
#define CRYPT_STRING_NOCRLF
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR _Inout_ DWORD * pcchString
#define CRYPT_STRING_NOCR
#define CRYPT_STRING_HEXASCIIADDR
#define ERROR_INVALID_DATA
static unsigned int block