40 #ifndef BOOST_BEAST_DETAIL_BASE64_HPP 41 #define BOOST_BEAST_DETAIL_BASE64_HPP 57 static char constexpr tab[] = {
58 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 67 static signed char constexpr tab[] = {
68 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
69 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
70 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
71 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
72 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
73 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
74 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
75 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
76 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
77 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
78 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
79 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
80 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
81 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
82 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
83 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
94 return 4 * ((n + 2) / 3);
118 template<
class =
void>
120 encode(
void* dest,
void const* src, std::size_t len)
122 char* out =
static_cast<char*
>(dest);
123 char const* in =
static_cast<char const*
>(src);
126 for(
auto n = len / 3; n--;)
128 *out++ = tab[ (in[0] & 0xfc) >> 2];
129 *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)];
130 *out++ = tab[((in[2] & 0xc0) >> 6) + ((in[1] & 0x0f) << 2)];
131 *out++ = tab[ in[2] & 0x3f];
138 *out++ = tab[ (in[0] & 0xfc) >> 2];
139 *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)];
140 *out++ = tab[ (in[1] & 0x0f) << 2];
145 *out++ = tab[ (in[0] & 0xfc) >> 2];
146 *out++ = tab[((in[0] & 0x03) << 4)];
155 return out -
static_cast<char*
>(dest);
169 template<
class =
void>
170 std::pair<std::size_t, std::size_t>
171 decode(
void* dest,
char const* src, std::size_t len)
173 char* out =
static_cast<char*
>(dest);
174 auto in =
reinterpret_cast<unsigned char const*
>(src);
175 unsigned char c3[3], c4[4];
181 while(len-- && *in !=
'=')
183 auto const v = inverse[*in];
190 c3[0] = (c4[0] << 2) + ((c4[1] & 0x30) >> 4);
191 c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2);
192 c3[2] = ((c4[2] & 0x3) << 6) + c4[3];
194 for(i = 0; i < 3; i++)
202 c3[0] = ( c4[0] << 2) + ((c4[1] & 0x30) >> 4);
203 c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2);
204 c3[2] = ((c4[2] & 0x3) << 6) + c4[3];
206 for(j = 0; j < i - 1; j++)
210 return {out -
static_cast<char*
>(dest),
211 in - reinterpret_cast<unsigned char const*>(src)};
216 template<
class =
void>
232 std::uint8_t
const*> (s.data()), s.size());
235 template<
class =
void>
242 &dest[0], data.data(), data.size());
243 dest.resize(result.first);
std::pair< std::size_t, std::size_t > decode(void *dest, char const *src, std::size_t len)
Definition: base64.hpp:171
Definition: async_result.hpp:20
std::string base64_decode(std::string const &data)
Definition: base64.hpp:237
std::string base64_encode(std::uint8_t const *data, std::size_t len)
Definition: base64.hpp:218
char const * get_alphabet()
Definition: base64.hpp:55
signed char const * get_inverse()
Definition: base64.hpp:65
std::size_t constexpr encoded_size(std::size_t n)
Returns max chars needed to encode a base64 string.
Definition: base64.hpp:92
std::size_t encode(void *dest, void const *src, std::size_t len)
Definition: base64.hpp:120
std::size_t constexpr decoded_size(std::size_t n)
Returns max bytes needed to decode a base64 string.
Definition: base64.hpp:100