13static const unsigned char pr2six[256] =
16 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
17 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
18 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
19 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
20 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
21 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
22 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
23 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
24 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
25 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
26 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
27 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
28 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
29 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
30 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
31 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 1, 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, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
156 register const unsigned char *bufin;
157 register int nprbytes;
159 bufin = (
const unsigned char *)
string -> data ;
160 while (
pr2six[*(bufin++)] <= 63);
162 nprbytes = (bufin - (
const unsigned char *)
string -> data) - 1;
163 nbytesdecoded = ((nprbytes + 3) / 4) * 3;
165 return nbytesdecoded ;
176 size_t nbytesdecoded;
177 register const unsigned char *bufin;
178 register unsigned char *bufout;
179 register int nprbytes;
181 bufin = (
const unsigned char *) bufcoded -> data ;
182 while (
pr2six[*(bufin++)] <= 63);
183 nprbytes = (bufin - (
const unsigned char *) bufcoded -> data) - 1;
184 nbytesdecoded = ( ( (nprbytes + 3) / 4) * 3 ) ;
187 bufout = (
unsigned char *) bufplain -> data ;
188 bufin = (
const unsigned char *) bufcoded -> data ;
190 while (nprbytes > 4) {
192 (
unsigned char) (
pr2six[*bufin] << 2 |
pr2six[bufin[1]] >> 4);
194 (
unsigned char) (
pr2six[bufin[1]] << 4 |
pr2six[bufin[2]] >> 2);
196 (
unsigned char) (
pr2six[bufin[2]] << 6 |
pr2six[bufin[3]]);
204 (
unsigned char) (
pr2six[*bufin] << 2 |
pr2six[bufin[1]] >> 4);
208 (
unsigned char) (
pr2six[bufin[1]] << 4 |
pr2six[bufin[2]] >> 2);
212 (
unsigned char) (
pr2six[bufin[2]] << 6 |
pr2six[bufin[3]]);
216 nbytesdecoded -= (4 - nprbytes) & 3;
218 bufplain -> written = nbytesdecoded ;
226"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
239 return ( (
string -> written + 2 ) / 3 * 4 ) + 1 ;
253 char *
string = input -> data ;
254 size_t len = input -> written ;
257 if( output_length == 0 )
262 p = encoded -> data ;
263 for (i = 0; i < len - 2; i += 3) {
264 *p++ =
basis_64[(
string[i] >> 2) & 0x3F];
265 *p++ =
basis_64[((
string[i] & 0x3) << 4) |
266 ((int) (
string[i + 1] & 0xF0) >> 4)];
267 *p++ =
basis_64[((
string[i + 1] & 0xF) << 2) |
268 ((int) (
string[i + 2] & 0xC0) >> 6)];
269 *p++ =
basis_64[
string[i + 2] & 0x3F];
272 *p++ =
basis_64[(
string[i] >> 2) & 0x3F];
273 if (i == (len - 1)) {
274 *p++ =
basis_64[((
string[i] & 0x3) << 4)];
278 *p++ =
basis_64[((
string[i] & 0x3) << 4) |
279 ((int) (
string[i + 1] & 0xF0) >> 4)];
280 *p++ =
basis_64[((
string[i + 1] & 0xF) << 2)];
287 encoded -> written = p - encoded -> data ;
#define __n_assert(__ptr, __ret)
macro to assert things
#define FORCE_INLINE
FORCE_INLINE portable macro.
FORCE_INLINE char n_tolower(char c)
is_alpha
N_STR * n_base64_decode(N_STR *bufcoded)
decode a N_STR *string
FORCE_INLINE bool n_isupper(char c)
test if char c is uppercase
FORCE_INLINE char n_toupper(char c)
is_alpha
FORCE_INLINE bool n_islower(char c)
test if char c is lowercase
FORCE_INLINE bool n_isalpha(char c)
is_alpha
N_STR * n_base64_encode(N_STR *input)
encode a N_STR *string
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
A box including a string and his lenght.
size_t n_base64_decode_len(N_STR *string)
get the length of 'input' if it was base64 decoded
static const char basis_64[]
static lookup base64 alphabet
static const bool ascii_upper_case_lookup_table[256]
static upper case lookup ascii table
static const bool ascii_lower_case_lookup_table[256]
static lower case lookup ascii table
size_t n_base64_encode_len(N_STR *string)
get the length of string if it was base64 encoded
static const unsigned char pr2six[256]
static lookup ascii table
base64 encoding and decoding functions using N_STR