1 #define _POSIX_C_SOURCE 200809L
10 static const unsigned char d[] = {
11 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 64, 66, 66, 66, 66, 66, 66,
12 66, 66, 66, 66, 66, 66, 66, 66,
13 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
14 66, 62, 66, 66, 66, 63, 52, 53,
15 54, 55, 56, 57, 58, 59, 60, 61, 66, 66, 66, 65, 66, 66, 66, 0, 1,
16 2, 3, 4, 5, 6, 7, 8, 9,
17 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 66,
18 66, 66, 66, 66, 66, 26, 27, 28,
19 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
20 46, 47, 48, 49, 50, 51, 66, 66,
21 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
22 66, 66, 66, 66, 66, 66, 66, 66,
23 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
24 66, 66, 66, 66, 66, 66, 66, 66,
25 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
26 66, 66, 66, 66, 66, 66, 66, 66,
27 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
28 66, 66, 66, 66, 66, 66, 66, 66,
29 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
30 66, 66, 66, 66, 66, 66, 66, 66,
31 66, 66, 66, 66, 66, 66
34 int base64decode(const char *in, size_t inLen, unsigned char *out,
36 const char *end = in + inLen;
42 unsigned char c = d[(int)(*in++)];
46 continue; /* skip whitespace */
48 return 0; /* invalid input, return error */
49 case EQUALS: /* pad character, end of data */
54 iter++; // increment the number of iteration
55 /* If the buffer is full, split it into bytes */
57 if ((len += 3) > *outLen)
58 return 0; /* buffer overflow */
59 *(out++) = (buf >> 16) & 255;
60 *(out++) = (buf >> 8) & 255;
70 if ((len += 2) > *outLen)
71 return 0; /* buffer overflow */
72 *(out++) = (buf >> 10) & 255;
73 *(out++) = (buf >> 2) & 255;
74 } else if (iter == 2) {
76 return 0; /* buffer overflow */
77 *(out++) = (buf >> 4) & 255;
80 *outLen = len; /* modify to reflect the actual output size */