16#if defined(__GNUG__) && !defined(__APPLE__)
17#pragma interface "base64.h"
22static const char base64_table[] = {
23 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
24 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
25 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
26 'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
27 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'+',
'/',
'\0'};
29static const char base64_pad =
'=';
31static const short base64_reverse_table[256] = {
32 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
34 -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
35 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
36 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
37 -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
38 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
39 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
40 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
45 -1, -1, -1, -1, -1, -1, -1, -1, -1};
49WXDLLIMPEXP_HTTPENGINE wxString wxBase64Encode(
const wxString &str) {
51 int length = str.Length();
57 szToReturn.Append(base64_table[str.GetChar(current) >> 2]);
58 szToReturn.Append(base64_table[((str.GetChar(current) & 0x03) << 4) +
59 (str.GetChar(current + 1) >> 4)]);
60 szToReturn.Append(base64_table[((str.GetChar(current + 1) & 0x0f) << 2) +
61 (str.GetChar(current + 2) >> 6)]);
62 szToReturn.Append(base64_table[str.GetChar(current + 2) & 0x3f]);
70 szToReturn.Append(base64_table[str.GetChar(current) >> 2]);
74 szToReturn.Append(base64_table[((str.GetChar(current) & 0x03) << 4) +
75 (str.GetChar(current + 1) >> 4)]);
76 szToReturn.Append(base64_table[(str.GetChar(current + 1) & 0x0f) << 2]);
77 szToReturn.Append(base64_pad);
79 szToReturn.Append(base64_table[(str.GetChar(current) & 0x03) << 4]);
80 szToReturn.Append(base64_pad);
81 szToReturn.Append(base64_pad);
90WXDLLIMPEXP_HTTPENGINE wxString wxBase64Decode(
const wxString &str) {
93 int length = str.Length();
94 unsigned int current = 0;
98 while (current != str.Length() && length-- > 0) {
99 ch = str.GetChar(current++);
101 if (ch == base64_pad)
break;
109 if (ch ==
' ') ch =
'+';
111 ch = base64_reverse_table[(int)ch];
112 if (ch < 0)
continue;
117 szToReturn.Append(ch << 2);
120 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch >> 4);
122 szToReturn.Append((ch & 0x0f) << 4);
125 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch >> 2);
127 szToReturn.Append((ch & 0x03) << 6);
130 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch);
139 if (ch == base64_pad) {
143 return wxEmptyString;