6 static const char base64t
[64] = {
7 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
8 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
9 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
10 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
11 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
12 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
13 'w', 'x', 'y', 'z', '0', '1', '2', '3',
14 '4', '5', '6', '7', '8', '9', '+', '/',
17 char *base64_to(char *dst
,const u8
*src
,size_t slen
)
24 for(size_t i
= 0; i
< slen
;) {
26 threebytes
|= (i
< slen
? (unsigned char)src
[i
++] : (unsigned char)0) << (2 * 8);
27 threebytes
|= (i
< slen
? (unsigned char)src
[i
++] : (unsigned char)0) << (1 * 8);
28 threebytes
|= (i
< slen
? (unsigned char)src
[i
++] : (unsigned char)0) << (0 * 8);
30 *dst
++ = base64t
[(threebytes
>> (3 * 6)) & 63];
31 *dst
++ = base64t
[(threebytes
>> (2 * 6)) & 63];
32 *dst
++ = base64t
[(threebytes
>> (1 * 6)) & 63];
33 *dst
++ = base64t
[(threebytes
>> (0 * 6)) & 63];