7 #pragma warning(disable : 4365 4987)
17static const char*
alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
20 return ((4ul * size / 3ul) + 3ul) & ~3ul;
24inline std::size_t
base64encode(
char* destination,
const char* source, std::size_t size) {
25 char* out = destination;
30 for (std::size_t pos = {}; pos < size; ++pos) {
31 const auto c =
static_cast<unsigned char>(source[pos]);
35 *out++ = (
alphabet[(val >> valb) & 0x3F]);
41 *out++ =
alphabet[((val << 8) >> (valb + 8)) & 0x3F];
44 while (
static_cast<std::size_t
>(out - destination) % 4) {
49 return static_cast<std::size_t
>(out - destination);
53 return (size * 3ul) / 4ul;
57inline std::size_t
base64decode(
char* destination,
const char* source, std::size_t size) {
58 char* out = destination;
61 std::fill_n(buffer, 256, -1);
62 for (
int i = 0; i < 64; i++) {
63 buffer[
static_cast<std::size_t
>(
alphabet[i])] = i;
69 for (std::size_t pos = {}; pos < size; ++pos) {
70 const auto c =
static_cast<unsigned char>(source[pos]);
71 if (buffer[c] == -1) {
74 val = (val << 6) + buffer[c];
77 *out++ =
static_cast<char>((val >> valb) & 0xFF);
83 return static_cast<std::size_t
>(out - destination);
static const char * alphabet
Definition: Base64.h:17
constexpr std::size_t base64decode(std::size_t size)
Definition: Base64.h:52
constexpr std::size_t base64encode(std::size_t size)
Definition: Base64.h:19