24#ifndef __BASE64_H_INCLUDED__
25#define __BASE64_H_INCLUDED__
45#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
49 "abcdefghijklmnopqrstuvwxyz"
71 -1, -1, -1, -1, -1, -1, -1, -1,
72 -1, -2, -2, -2, -2, -2, -1, -1,
73 -1, -1, -1, -1, -1, -1, -1, -1,
74 -1, -1, -1, -1, -1, -1, -1, -1,
75 -2, -1, -1, -1, -1, -1, -1, -1,
76 -1, -1, -1, 62, -1, -1, -1, 63,
77 52, 53, 54, 55, 56, 57, 58, 59,
78 60, 61, -1, -1, -1, -1, -1, -1,
79 -1, 0, 1, 2, 3, 4, 5, 6,
80 7, 8, 9, 10, 11, 12, 13, 14,
81 15, 16, 17, 18, 19, 20, 21, 22,
82 23, 24, 25, -1, -1, -1, -1, -1,
83 -1, 26, 27, 28, 29, 30, 31, 32,
84 33, 34, 35, 36, 37, 38, 39, 40,
85 41, 42, 43, 44, 45, 46, 47, 48,
86 49, 50, 51, -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 -1, -1, -1, -1, -1, -1, -1, -1,
91 -2, -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,
102 -1, -1, -1, -1, -1, -1, -1, -1};
119 for (; decoder->
src < decoder->
end; decoder->
src++) {
122 if (decoder->
state > 0)
142 return (decoder->
error =
true);
143 decoder->
c += (
uint)res;
164 assert(decoder->
state == 3);
174 switch (decoder->
state) {
182 if (decoder->
src[-1] ==
'=') {
205 if (length_of_data == 0)
return 1;
206 nb_base64_chars = (length_of_data + 2) / 3 * 4;
208 return nb_base64_chars +
209 (nb_base64_chars - 1) / 76 +
217#if (SIZEOF_VOIDP == 8)
222 return 0x5EC0D4C77B03531BLL;
236 uint64 length_of_encoded_data) {
237 return static_cast<uint64>(
238 ceil(
static_cast<double>(length_of_encoded_data * 3 / 4)));
245#if (SIZEOF_VOIDP == 8)
246 return 0x2AAAAAAAAAAAAAAALL;
255static inline int base64_encode(
const void *src,
size_t src_len,
char *dst) {
256 const unsigned char *s = (
const unsigned char *)src;
260 for (; i < src_len; len += 4) {
271 if (i < src_len) c += s[i];
275 if (i < src_len) c += s[i];
281 if (i > (src_len + 1))
317 const char **end_ptr,
int flags) {
318 char *d = (
char *)dst;
321 decoder.
src = src_base;
322 decoder.
end = src_base + len;
335 *d++ = (decoder.
c >> 16) & 0xff;
336 *d++ = (decoder.
c >> 8) & 0xff;
337 *d++ = (decoder.
c >> 0) & 0xff;
350 if (end_ptr !=
nullptr) *end_ptr = decoder.
src;
352 return decoder.
error ? -1 : (int)(d - (
char *)dst);
static int flags[50]
Definition: hp_test1.cc:40
static bool my_base64_decoder_getch(MY_BASE64_DECODER *decoder)
Get the next character from a base64 encoded stream.
Definition: base64.h:157
static uint64 base64_encode_max_arg_length()
Definition: base64.h:216
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:138
static char base64_table[]
Definition: base64.h:47
static uint64 base64_needed_decoded_length(uint64 length_of_encoded_data)
Definition: base64.h:235
#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS
Definition: base64.h:45
struct my_base64_decoder_t MY_BASE64_DECODER
static int8 from_base64_table[]
Definition: base64.h:70
static uint64 base64_needed_encoded_length(uint64 length_of_data)
Definition: base64.h:203
static uint64 base64_decode_max_arg_length()
Definition: base64.h:244
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:316
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:118
static int base64_encode(const void *src, size_t src_len, char *dst)
Definition: base64.h:255
if(!(yy_init))
Definition: lexyy.cc:1144
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
int64_t int64
Definition: my_inttypes.h:68
int8_t int8
Definition: my_inttypes.h:62
uint64_t uint64
Definition: my_inttypes.h:69
uchar mark
Definition: base64.h:61
int error
Definition: base64.h:59
uchar state
Definition: base64.h:60
const char * end
Definition: base64.h:57
uint c
Definition: base64.h:58
const char * src
Definition: base64.h:56
unsigned int uint
Definition: uca9-dump.cc:75