11static const char *b64alpha =
12 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
31 while (in[l-1] ==
B64PAD) {
42 for (i = 0; i < n - 1 ; i++) {
44 for (j = 0; j < 4; j++) {
45 if(in[j] >=
'A' && in[j] <=
'Z')
46 x = (x << 6) + (
unsigned int)(in[j] -
'A' + 0);
47 else if(in[j] >=
'a' && in[j] <=
'z')
48 x = (x << 6) + (
unsigned int)(in[j] -
'a' + 26);
49 else if(in[j] >=
'0' && in[j] <=
'9')
50 x = (x << 6) + (
unsigned int)(in[j] -
'0' + 52);
59 s[2] = (
unsigned char)(x & 255); x >>= 8;
60 s[1] = (
unsigned char)(x & 255); x >>= 8;
61 s[0] = (
unsigned char)(x & 255); x >>= 8;
66 for (j = 0; j < 4; j++) {
67 if(in[j] >=
'A' && in[j] <=
'Z')
68 x = (x << 6) + (
unsigned int)(in[j] -
'A' + 0);
69 else if(in[j] >=
'a' && in[j] <=
'z')
70 x = (x << 6) + (
unsigned int)(in[j] -
'a' + 26);
71 else if(in[j] >=
'0' && in[j] <=
'9')
72 x = (x << 6) + (
unsigned int)(in[j] -
'0' + 52);
81 b[2] = (
unsigned char)(x & 255); x >>= 8;
82 b[1] = (
unsigned char)(x & 255); x >>= 8;
83 b[0] = (
unsigned char)(x & 255); x >>= 8;
85 for (i = 0; i < 3 - p; i++)
93 unsigned char a, b, c;
102 i = in->
len / 3 * 4 + 4;
106 for (i = 0; i < in->
len; i += 3) {
108 b = i + 1 < in->
len ? in->
s[i + 1] : 0;
109 c = i + 2 < in->
len ? in->
s[i + 2] : 0;
111 *s++ = b64alpha[a >> 2];
112 *s++ = b64alpha[((a & 3 ) << 4) | (b >> 4)];
115 else *s++ = b64alpha[((b & 15) << 2) | (c >> 6)];
118 else *s++ = b64alpha[c & 63];
120 out->
len = s - out->
s;
int b64encode(stralloc *in, stralloc *out)
int b64decode(const unsigned char *in, int l, stralloc *out)
int stralloc_ready(stralloc *sa, size_t len)
int stralloc_copys(stralloc *, const char *)