32 #ifdef SOCKETS_NAMESPACE
33 namespace SOCKETS_NAMESPACE {
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
47 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
48 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
49 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
50 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
51 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0};
62 remain = fread(input,1,3,fil);
65 if (add_crlf && o && o % 76 == 0)
70 output += bstr[ ((input[i] >> 2) & 0x3f) ];
71 output += bstr[ ((input[i] << 4) & 0x30) ];
75 output += bstr[ ((input[i] >> 2) & 0x3f) ];
76 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
77 output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
81 output += bstr[ ((input[i] >> 2) & 0x3f) ];
82 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
83 output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
84 output += bstr[ (input[i + 2] & 0x3f) ];
88 remain = fread(input,1,3,fil);
93 void Base64::encode(
const std::string& str_in, std::string& str_out,
bool add_crlf)
95 encode(str_in.c_str(), str_in.size(), str_out, add_crlf);
99 void Base64::encode(
const char* input,
size_t l,std::string& output,
bool add_crlf)
107 size_t remain = l - i;
108 if (add_crlf && o && o % 76 == 0)
113 output += bstr[ ((input[i] >> 2) & 0x3f) ];
114 output += bstr[ ((input[i] << 4) & 0x30) ];
118 output += bstr[ ((input[i] >> 2) & 0x3f) ];
119 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
120 output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
124 output += bstr[ ((input[i] >> 2) & 0x3f) ];
125 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
126 output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
127 output += bstr[ (input[i + 2] & 0x3f) ];
135 void Base64::encode(
unsigned char* input,
size_t l,std::string& output,
bool add_crlf)
143 size_t remain = l - i;
144 if (add_crlf && o && o % 76 == 0)
149 output += bstr[ ((input[i] >> 2) & 0x3f) ];
150 output += bstr[ ((input[i] << 4) & 0x30) ];
154 output += bstr[ ((input[i] >> 2) & 0x3f) ];
155 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
156 output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
160 output += bstr[ ((input[i] >> 2) & 0x3f) ];
161 output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
162 output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
163 output += bstr[ (input[i + 2] & 0x3f) ];
174 size_t l = input.size();
179 while (i < l && (input[i] == 13 || input[i] == 10))
183 char b1 = (char)((rstr[(
int)input[i]] << 2 & 0xfc) +
184 (rstr[(int)input[i + 1]] >> 4 & 0x03));
186 if (input[i + 2] !=
'=')
188 char b2 = (char)((rstr[(
int)input[i + 1]] << 4 & 0xf0) +
189 (rstr[(
int)input[i + 2]] >> 2 & 0x0f));
192 if (input[i + 3] !=
'=')
194 char b3 = (char)((rstr[(
int)input[i + 2]] << 6 & 0xc0) +
195 rstr[(
int)input[i + 3]]);
207 size_t l = input.size();
212 while (i < l && (input[i] == 13 || input[i] == 10))
216 unsigned char b1 = (
unsigned char)((rstr[(
int)input[i]] << 2 & 0xfc) +
217 (rstr[(int)input[i + 1]] >> 4 & 0x03));
223 if (input[i + 2] !=
'=')
225 unsigned char b2 = (
unsigned char)((rstr[(
int)input[i + 1]] << 4 & 0xf0) +
226 (rstr[(
int)input[i + 2]] >> 2 & 0x0f));
233 if (input[i + 3] !=
'=')
235 unsigned char b3 = (
unsigned char)((rstr[(
int)input[i + 2]] << 6 & 0xc0) +
236 rstr[(
int)input[i + 3]]);
252 if (!str64.size() || str64.size() % 4)
254 size_t l = 3 * (str64.size() / 4 - 1) + 1;
255 if (str64[str64.size() - 2] !=
'=')
257 if (str64[str64.size() - 1] !=
'=')
263 #ifdef SOCKETS_NAMESPACE
static size_t decode_length(const std::string &)
static const char rstr[128]
static void decode(const std::string &, std::string &)
static void encode(FILE *, std::string &, bool add_crlf=true)