#include "common.h"#include "base64.h"Include dependency graph for base64.c:

Go to the source code of this file.
Functions | |
| char * | base64Encode (char *input, size_t inplen) |
| boolean | base64Validate (char *input) |
| char * | base64Decode (char *input, size_t *returnSize) |
| char* base64Decode | ( | char * | input, | |
| size_t * | returnSize | |||
| ) |
Definition at line 78 of file base64.c.
References B64CHARS, and needMem().
00080 : big-endian algorithm. 00081 * Call eraseWhiteSpace() and check for invalid input 00082 * before passing in input if needed. 00083 * Optionally set return size for use with binary data. 00084 */ 00085 { 00086 static int *map=NULL; 00087 char b64[] = B64CHARS; 00088 size_t inplen = strlen(input); 00089 int words = (inplen+3)/4; 00090 char *result = (char *)needMem(3*words+1); 00091 size_t i=0, j=0; 00092 int word = 0; 00093 char *p = input; 00094 00095 if (!map) 00096 { 00097 int i = 0; 00098 map = needMem(256*sizeof(int)); 00099 for (i = 0; i < 256; ++i) 00100 { 00101 map[i]=0; 00102 } 00103 for (i = 0; i < 64; ++i) 00104 { 00105 map[(int)b64[i]]=i; 00106 } 00107 } 00108 for(i=0; i<words; i++) 00109 { 00110 word = 0; 00111 word |= map[(int)*p++]; 00112 word <<= 6; 00113 word |= map[(int)*p++]; 00114 word <<= 6; 00115 word |= map[(int)*p++]; 00116 word <<= 6; 00117 word |= map[(int)*p++]; 00118 result[j++]=word >> 16 & 0xFF; 00119 result[j++]=word >> 8 & 0xFF; 00120 result[j++]=word & 0xFF; 00121 } 00122 result[j] = 0; 00123 if (returnSize) 00124 *returnSize = j; 00125 00126 return result; 00127 }
Here is the call graph for this function:

| char* base64Encode | ( | char * | input, | |
| size_t | inplen | |||
| ) |
Definition at line 4 of file base64.c.
References B64CHARS, and needMem().
Referenced by netHttpConnect(), and netHttpGet().
00006 : big-endian algorithm. 00007 * For some applications you may need to break the base64 output 00008 * of this function into lines no longer than 76 chars. 00009 */ 00010 { 00011 char b64[] = B64CHARS; 00012 int words = (inplen+2)/3; 00013 int remains = inplen % 3; 00014 char *result = (char *)needMem(4*words+1); 00015 size_t i=0, j=0; 00016 int word = 0; 00017 unsigned char *p = (unsigned char*) input; 00018 /* p must be unsigned char*, because without "unsigned", 00019 sign extend messes up last group outputted 00020 when the value of the chars following last in input 00021 happens to be char 0x80 or higher */ 00022 for(i=1; i<=words; i++) 00023 { 00024 word = 0; 00025 word |= *p++; 00026 word <<= 8; 00027 word |= *p++; 00028 word <<= 8; 00029 word |= *p++; 00030 if (i==words && remains>0) 00031 { 00032 word &= 0x00FFFF00; 00033 if (remains==1) 00034 word &= 0x00FF0000; 00035 } 00036 result[j++]=b64[word >> 18 & 0x3F]; 00037 result[j++]=b64[word >> 12 & 0x3F]; 00038 result[j++]=b64[word >> 6 & 0x3F]; 00039 result[j++]=b64[word & 0x3F]; 00040 } 00041 result[j] = 0; 00042 if (remains >0) result[j-1] = '='; 00043 if (remains==1) result[j-2] = '='; 00044 return result; 00045 }
Here is the call graph for this function:

Here is the caller graph for this function:

| boolean base64Validate | ( | char * | input | ) |
Definition at line 48 of file base64.c.
References B64CHARS, eraseWhiteSpace(), FALSE, and TRUE.
00052 { 00053 size_t i = 0, l = 0; 00054 char *p = input; 00055 boolean validB64 = TRUE; 00056 00057 /* remove whitespace which is unnecessary and */ 00058 eraseWhiteSpace(input); 00059 00060 l = strlen(p); 00061 for(i=0;i<l;i++) 00062 { 00063 char c = ' '; 00064 if (!strchr(B64CHARS,c=*p++)) 00065 { 00066 if (c != '=') 00067 { 00068 validB64 = FALSE; 00069 break; 00070 } 00071 } 00072 } 00073 if (l%4) 00074 validB64 = FALSE; 00075 return validB64; 00076 }
Here is the call graph for this function:

1.5.2