diff options
Diffstat (limited to 'src/microhttpd/base64.c')
-rw-r--r-- | src/microhttpd/base64.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/microhttpd/base64.c b/src/microhttpd/base64.c index 3dc7a142..d7d1ec92 100644 --- a/src/microhttpd/base64.c +++ b/src/microhttpd/base64.c | |||
@@ -9,45 +9,46 @@ | |||
9 | #include "base64.h" | 9 | #include "base64.h" |
10 | 10 | ||
11 | static const char base64_digits[] = | 11 | static const char base64_digits[] = |
12 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 12 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
13 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 13 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
14 | 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, | 14 | 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, |
15 | 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, | 15 | 0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, |
16 | 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, | 16 | 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, |
17 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, | 17 | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, |
18 | 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 18 | 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
19 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 19 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
20 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 20 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
21 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 21 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
23 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | 23 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
24 | 24 | ||
25 | 25 | ||
26 | char * | 26 | char * |
27 | BASE64Decode(const char* src) | 27 | BASE64Decode (const char*src) |
28 | { | 28 | { |
29 | size_t in_len = strlen (src); | 29 | size_t in_len = strlen (src); |
30 | char* dest; | 30 | char*dest; |
31 | char* result; | 31 | char*result; |
32 | 32 | ||
33 | if (in_len % 4) | 33 | if (in_len % 4) |
34 | { | 34 | { |
35 | /* Wrong base64 string length */ | 35 | /* Wrong base64 string length */ |
36 | return NULL; | 36 | return NULL; |
37 | } | 37 | } |
38 | result = dest = malloc(in_len / 4 * 3 + 1); | 38 | result = dest = malloc (in_len / 4 * 3 + 1); |
39 | if (NULL == result) | 39 | if (NULL == result) |
40 | return NULL; /* out of memory */ | 40 | return NULL; /* out of memory */ |
41 | while (*src) { | 41 | while (*src) |
42 | char a = base64_digits[(unsigned char)*(src++)]; | 42 | { |
43 | char b = base64_digits[(unsigned char)*(src++)]; | 43 | char a = base64_digits[(unsigned char) *(src++)]; |
44 | char c = base64_digits[(unsigned char)*(src++)]; | 44 | char b = base64_digits[(unsigned char) *(src++)]; |
45 | char d = base64_digits[(unsigned char)*(src++)]; | 45 | char c = base64_digits[(unsigned char) *(src++)]; |
46 | char d = base64_digits[(unsigned char) *(src++)]; | ||
46 | *(dest++) = (a << 2) | ((b & 0x30) >> 4); | 47 | *(dest++) = (a << 2) | ((b & 0x30) >> 4); |
47 | if (c == (char)-1) | 48 | if (c == (char) -1) |
48 | break; | 49 | break; |
49 | *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2); | 50 | *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2); |
50 | if (d == (char)-1) | 51 | if (d == (char) -1) |
51 | break; | 52 | break; |
52 | *(dest++) = ((c & 0x03) << 6) | d; | 53 | *(dest++) = ((c & 0x03) << 6) | d; |
53 | } | 54 | } |