20#if defined(__GNUG__) && !defined(__APPLE__)
21#pragma interface "base64.h"
26static const char base64_table[] = {
27 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
28 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
29 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
30 'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
31 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'+',
'/',
'\0'};
33static const char base64_pad =
'=';
35static const short base64_reverse_table[256] = {
36 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38 -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60,
39 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
40 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
41 -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
42 43, 44, 45, 46, 47, 48, 49, 50, 51, -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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
49 -1, -1, -1, -1, -1, -1, -1, -1, -1};
55 int length = str.Length();
61 szToReturn.Append(base64_table[str.GetChar(current) >> 2]);
62 szToReturn.Append(base64_table[((str.GetChar(current) & 0x03) << 4) +
63 (str.GetChar(current + 1) >> 4)]);
64 szToReturn.Append(base64_table[((str.GetChar(current + 1) & 0x0f) << 2) +
65 (str.GetChar(current + 2) >> 6)]);
66 szToReturn.Append(base64_table[str.GetChar(current + 2) & 0x3f]);
74 szToReturn.Append(base64_table[str.GetChar(current) >> 2]);
78 szToReturn.Append(base64_table[((str.GetChar(current) & 0x03) << 4) +
79 (str.GetChar(current + 1) >> 4)]);
80 szToReturn.Append(base64_table[(str.GetChar(current + 1) & 0x0f) << 2]);
81 szToReturn.Append(base64_pad);
83 szToReturn.Append(base64_table[(str.GetChar(current) & 0x03) << 4]);
84 szToReturn.Append(base64_pad);
85 szToReturn.Append(base64_pad);
97 int length = str.Length();
98 unsigned int current = 0;
102 while (current != str.Length() && length-- > 0) {
103 ch = str.GetChar(current++);
105 if (ch == base64_pad)
break;
113 if (ch ==
' ') ch =
'+';
115 ch = base64_reverse_table[(int)ch];
116 if (ch < 0)
continue;
121 szToReturn.Append(ch << 2);
124 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch >> 4);
126 szToReturn.Append((ch & 0x0f) << 4);
129 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch >> 2);
131 szToReturn.Append((ch & 0x03) << 6);
134 szToReturn.SetChar(j, szToReturn.GetChar(j) | ch);
143 if (ch == base64_pad) {
WXDLLIMPEXP_HTTPENGINE wxString wxBase64Decode(const wxString &str)
Returns string base64 decoded.
WXDLLIMPEXP_HTTPENGINE wxString wxBase64Encode(const wxString &str)
Returns string base64 encoded.