26 static const unsigned char pr2six[256] =
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, 62, 64, 64, 64, 63,
32 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
33 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
34 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
35 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
36 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
37 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
38 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
39 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
40 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
41 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
42 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
43 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
44 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
50 register const unsigned char *bufin;
51 register int nprbytes;
53 bufin = (
const unsigned char *) bufcoded;
54 while (
pr2six[*(bufin++)] <= 63 && buflen-- > 0);
56 nprbytes = (bufin - (
const unsigned char *) bufcoded) - 1;
57 nbytesdecoded = (((int)nprbytes + 3) / 4) * 3;
59 return nbytesdecoded + 1;
74 const char *bufcoded,
int buflen)
77 register const unsigned char *bufin;
78 register unsigned char *bufout;
79 register int nprbytes;
81 bufin = (
const unsigned char *) bufcoded;
82 while (
pr2six[*(bufin++)] <= 63 && buflen-- > 0);
83 nprbytes = (bufin - (
const unsigned char *) bufcoded) - 1;
84 nbytesdecoded = (((int)nprbytes + 3) / 4) * 3;
86 bufout = (
unsigned char *) bufplain;
87 bufin = (
const unsigned char *) bufcoded;
89 while (nprbytes > 4) {
91 (
unsigned char) (
pr2six[*bufin] << 2 |
pr2six[bufin[1]] >> 4);
93 (
unsigned char) (
pr2six[bufin[1]] << 4 |
pr2six[bufin[2]] >> 2);
95 (
unsigned char) (
pr2six[bufin[2]] << 6 |
pr2six[bufin[3]]);
103 (
unsigned char) (
pr2six[*bufin] << 2 |
pr2six[bufin[1]] >> 4);
107 (
unsigned char) (
pr2six[bufin[1]] << 4 |
pr2six[bufin[2]] >> 2);
111 (
unsigned char) (
pr2six[bufin[2]] << 6 |
pr2six[bufin[3]]);
114 nbytesdecoded -= (4 - (int)nprbytes) & 3;
115 return nbytesdecoded;
119 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
123 return ((len + 2) / 3 * 4) + 1;
134 const unsigned char *
string,
int len)
140 for (i = 0; i < len - 2; i += 3) {
141 *p++ =
basis_64[(
string[i] >> 2) & 0x3F];
142 *p++ =
basis_64[((
string[i] & 0x3) << 4) |
143 ((int) (
string[i + 1] & 0xF0) >> 4)];
144 *p++ =
basis_64[((
string[i + 1] & 0xF) << 2) |
145 ((int) (
string[i + 2] & 0xC0) >> 6)];
146 *p++ =
basis_64[
string[i + 2] & 0x3F];
149 *p++ =
basis_64[(
string[i] >> 2) & 0x3F];
150 if (i == (len - 1)) {
151 *p++ =
basis_64[((
string[i] & 0x3) << 4)];
155 *p++ =
basis_64[((
string[i] & 0x3) << 4) |
156 ((int) (
string[i + 1] & 0xF0) >> 4)];
157 *p++ =
basis_64[((
string[i + 1] & 0xF) << 2)];
163 return (
int)(p - encoded);
175 out = (
char *) malloc(
sizeof(
char) * (elen + 1));
189 out = (
char *) malloc(
sizeof(
char) * (elen + 1));
int apr_base64_encode_binary(char *encoded, const unsigned char *string, int len)
char * b64_encode(char *buf, int len)
int apr_base64_decode(char *bufplain, const char *bufcoded, int buflen)
int apr_base64_decode_len(const char *bufcoded, int buflen)
int apr_base64_encode(char *encoded, const char *string, int len)
static const unsigned char pr2six[256]
char * b64_decode(char *buf)
int apr_base64_encode_len(int len)
int apr_base64_decode_binary(unsigned char *bufplain, const char *bufcoded, int buflen)
static const char basis_64[]