diff options
author | Daniel Stenberg <daniel@haxx.se> | 2000-09-21 08:46:44 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2000-09-21 08:46:44 +0000 |
commit | 37249c3a4161c9cfa88b4f2fd86f12d3ee61fdb2 (patch) | |
tree | bfcda37a3538d86eefbab1c5d89a2cd4891dea74 /lib | |
parent | def69c30879c0246bccb02d79e06b937e39d0ba4 (diff) |
new interface to the base64 encoder
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base64.c | 34 | ||||
-rw-r--r-- | lib/base64.h | 2 |
2 files changed, 30 insertions, 6 deletions
diff --git a/lib/base64.c b/lib/base64.c index c857fbce3..67204771a 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -44,19 +44,40 @@ static char table64[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -void base64Encode(char *intext, char *output) +/* + * base64Encode() + * + * Returns the length of the newly created base64 string. The third argument + * is a pointer to an allocated area holding the base64 data. If something + * went wrong, -1 is returned. + * + * Modifed my version to resemble the krb4 one. The krb4 sources then won't + * need its own. + * + */ +int base64Encode(char *indata, int insize, char **outptr) { unsigned char ibuf[3]; unsigned char obuf[4]; int i; int inputparts; + char *output; + char *base64data; - while(*intext) { + if(0 == insize) + insize = strlen(indata); + + base64data = output = (char*)malloc(insize*4/3+4); + if(NULL == output) + return -1; + + while(insize > 0) { for (i = inputparts = 0; i < 3; i++) { - if(*intext) { + if(*indata) { inputparts++; - ibuf[i] = *intext; - intext++; + ibuf[i] = *indata; + indata++; + insize--; } else ibuf[i] = 0; @@ -90,5 +111,8 @@ void base64Encode(char *intext, char *output) output += 4; } *output=0; + *outptr = base64data; /* make it return the actual data memory */ + + return strlen(base64data); /* return the length of the new data */ } /* ---- End of Base64 Encoding ---- */ diff --git a/lib/base64.h b/lib/base64.h index d8770f325..05ff71f0c 100644 --- a/lib/base64.h +++ b/lib/base64.h @@ -40,5 +40,5 @@ * ------------------------------------------------------------ ****************************************************************************/ -void base64Encode(char *intext, char *output); +int base64Encode(char *indata, int insize, char **output); #endif |