23#ifndef __BASE64_H_INCLUDED__
24#define __BASE64_H_INCLUDED__
44#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
48 "abcdefghijklmnopqrstuvwxyz"
70 -1, -1, -1, -1, -1, -1, -1, -1,
71 -1, -2, -2, -2, -2, -2, -1, -1,
72 -1, -1, -1, -1, -1, -1, -1, -1,
73 -1, -1, -1, -1, -1, -1, -1, -1,
74 -2, -1, -1, -1, -1, -1, -1, -1,
75 -1, -1, -1, 62, -1, -1, -1, 63,
76 52, 53, 54, 55, 56, 57, 58, 59,
77 60, 61, -1, -1, -1, -1, -1, -1,
78 -1, 0, 1, 2, 3, 4, 5, 6,
79 7, 8, 9, 10, 11, 12, 13, 14,
80 15, 16, 17, 18, 19, 20, 21, 22,
81 23, 24, 25, -1, -1, -1, -1, -1,
82 -1, 26, 27, 28, 29, 30, 31, 32,
83 33, 34, 35, 36, 37, 38, 39, 40,
84 41, 42, 43, 44, 45, 46, 47, 48,
85 49, 50, 51, -1, -1, -1, -1, -1,
86 -1, -1, -1, -1, -1, -1, -1, -1,
87 -1, -1, -1, -1, -1, -1, -1, -1,
88 -1, -1, -1, -1, -1, -1, -1, -1,
89 -1, -1, -1, -1, -1, -1, -1, -1,
90 -2, -1, -1, -1, -1, -1, -1, -1,
91 -1, -1, -1, -1, -1, -1, -1, -1,
92 -1, -1, -1, -1, -1, -1, -1, -1,
93 -1, -1, -1, -1, -1, -1, -1, -1,
94 -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, -1, -1, -1, -1, -1,
97 -1, -1, -1, -1, -1, -1, -1, -1,
98 -1, -1, -1, -1, -1, -1, -1, -1,
99 -1, -1, -1, -1, -1, -1, -1, -1,
100 -1, -1, -1, -1, -1, -1, -1, -1,
101 -1, -1, -1, -1, -1, -1, -1, -1};
118 for (; decoder->
src < decoder->
end; decoder->
src++) {
121 if (decoder->
state > 0)
141 return (decoder->
error =
true);
142 decoder->
c += (uint)res;
163 assert(decoder->
state == 3);
173 switch (decoder->
state) {
181 if (decoder->
src[-1] ==
'=') {
204 if (length_of_data == 0)
return 1;
205 nb_base64_chars = (length_of_data + 2) / 3 * 4;
207 return nb_base64_chars +
208 (nb_base64_chars - 1) / 76 +
216#if (SIZEOF_VOIDP == 8)
221 return 0x5EC0D4C77B03531BLL;
235 uint64 length_of_encoded_data) {
236 return static_cast<uint64>(
237 ceil(
static_cast<double>(length_of_encoded_data * 3 / 4)));
244#if (SIZEOF_VOIDP == 8)
245 return 0x2AAAAAAAAAAAAAAALL;
254static inline int base64_encode(
const void *src,
size_t src_len,
char *dst) {
255 const unsigned char *s = (
const unsigned char *)src;
259 for (; i < src_len; len += 4) {
270 if (i < src_len) c += s[i];
274 if (i < src_len) c += s[i];
280 if (i > (src_len + 1))
316 const char **end_ptr,
int flags) {
317 char *d = (
char *)dst;
320 decoder.
src = src_base;
321 decoder.
end = src_base + len;
334 *d++ = (decoder.
c >> 16) & 0xff;
335 *d++ = (decoder.
c >> 8) & 0xff;
336 *d++ = (decoder.
c >> 0) & 0xff;
349 if (end_ptr !=
nullptr) *end_ptr = decoder.
src;
351 return decoder.
error ? -1 : (int)(d - (
char *)dst);
static int flags[50]
Definition: hp_test1.cc:39
static bool my_base64_decoder_getch(MY_BASE64_DECODER *decoder)
Get the next character from a base64 encoded stream.
Definition: base64.h:156
static uint64 base64_encode_max_arg_length()
Definition: base64.h:215
static bool my_base64_add(MY_BASE64_DECODER *decoder)
Convert the next character in a base64 encoded stream to a number in the range [0....
Definition: base64.h:137
static char base64_table[]
Definition: base64.h:46
static uint64 base64_needed_decoded_length(uint64 length_of_encoded_data)
Definition: base64.h:234
#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS
Definition: base64.h:44
struct my_base64_decoder_t MY_BASE64_DECODER
static int8 from_base64_table[]
Definition: base64.h:69
static uint64 base64_needed_encoded_length(uint64 length_of_data)
Definition: base64.h:202
static uint64 base64_decode_max_arg_length()
Definition: base64.h:243
static int64 base64_decode(const char *src_base, size_t len, void *dst, const char **end_ptr, int flags)
Decode a base64 string The base64-encoded data in the range ['src','*end_ptr') will be decoded and st...
Definition: base64.h:315
static bool my_base64_decoder_skip_spaces(MY_BASE64_DECODER *decoder)
Skip leading spaces in a base64 encoded stream and stop on the first non-space character.
Definition: base64.h:117
static int base64_encode(const void *src, size_t src_len, char *dst)
Definition: base64.h:254
if(!(yy_init))
Definition: lexyy.cc:1144
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
int8_t int8
Definition: my_inttypes.h:61
uint64_t uint64
Definition: my_inttypes.h:68
uchar mark
Definition: base64.h:60
int error
Definition: base64.h:58
uchar state
Definition: base64.h:59
const char * end
Definition: base64.h:56
uint c
Definition: base64.h:57
const char * src
Definition: base64.h:55