44 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 45 "abcdefghijklmnopqrstuvwxyz" 55 (c >= 47 && c <= 57) ||
56 (c >= 65 && c <= 90) ||
57 (c >= 97 && c <= 122));
66 inline std::string
base64_encode(
unsigned char const * input,
size_t len) {
70 unsigned char char_array_3[3];
71 unsigned char char_array_4[4];
74 char_array_3[i++] = *(input++);
76 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
77 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
78 ((char_array_3[1] & 0xf0) >> 4);
79 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
80 ((char_array_3[2] & 0xc0) >> 6);
81 char_array_4[3] = char_array_3[2] & 0x3f;
83 for(i = 0; (i <4) ; i++) {
84 ret += base64_chars[char_array_4[i]];
91 for(j = i; j < 3; j++) {
92 char_array_3[j] =
'\0';
95 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
96 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
97 ((char_array_3[1] & 0xf0) >> 4);
98 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
99 ((char_array_3[2] & 0xc0) >> 6);
100 char_array_4[3] = char_array_3[2] & 0x3f;
102 for (j = 0; (j < i + 1); j++) {
103 ret += base64_chars[char_array_4[j]];
121 reinterpret_cast<const unsigned char *>(input.data()),
132 size_t in_len = input.size();
136 unsigned char char_array_4[4], char_array_3[3];
139 while (in_len-- && ( input[in_] !=
'=') &&
is_base64(input[in_])) {
140 char_array_4[i++] = input[in_]; in_++;
142 for (i = 0; i <4; i++) {
143 char_array_4[i] =
static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
146 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
147 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
148 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
150 for (i = 0; (i < 3); i++) {
151 ret += char_array_3[i];
158 for (j = i; j <4; j++)
161 for (j = 0; j <4; j++)
162 char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
164 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
165 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
166 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
168 for (j = 0; (j < i - 1); j++) {
169 ret +=
static_cast<std::string::value_type
>(char_array_3[j]);
178 #endif // _BASE64_HPP_ static bool is_base64(unsigned char c)
Test whether a character is a valid base64 character.
std::string base64_encode(unsigned char const *input, size_t len)
Encode a char buffer into a base64 string.
std::string base64_decode(std::string const &input)
Decode a base64 encoded string into a string of raw bytes.
static std::string const base64_chars
Namespace for the WebSocket++ project.