Commit af4c3599 authored by Geoff Simmons's avatar Geoff Simmons

use the base64 code from varnishncsa 4.0.3 (public domain)

parent 3deed825
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include "config.h" #include "config.h"
#include <sys/types.h> #include <stdlib.h>
#include "varnishapi.h" #include <string.h>
#include "base64.h" #include "base64.h"
static const char b64[] = static const char b64[] =
...@@ -29,17 +30,17 @@ VB64_init(void) ...@@ -29,17 +30,17 @@ VB64_init(void)
} }
int int
VB64_decode(char *d, unsigned dlen, const char *s) VB64_decode(char *d, unsigned dlen, const char *s, const char *e)
{ {
unsigned u, v, l; unsigned u, v, l;
int i; int i;
if (e == NULL)
e = s + strlen(s);
u = 0; u = 0;
l = 0; l = 0;
while (*s) { while (s < e) {
for (v = 0; v < 4; v++) { for (v = 0; s < e && v < 4; v++) {
if (!*s)
break;
i = i64[(int)*s++]; i = i64[(int)*s++];
if (i < 0) if (i < 0)
return (-1); return (-1);
...@@ -60,7 +61,8 @@ VB64_decode(char *d, unsigned dlen, const char *s) ...@@ -60,7 +61,8 @@ VB64_decode(char *d, unsigned dlen, const char *s)
} }
#ifdef TEST_DRIVER #ifdef TEST_DRIVER
#include <stdio.h>
#include <stdio.h> // for test-prog
const char *test1 = const char *test1 =
"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
...@@ -81,7 +83,7 @@ main(int argc, char **argv) ...@@ -81,7 +83,7 @@ main(int argc, char **argv)
VB64_init(); VB64_init();
l = sizeof buf; l = sizeof buf;
VB64_decode(buf, &l, test1); VB64_decode(buf, l, test1, NULL);
printf("%s\n", buf); printf("%s\n", buf);
return (0); return (0);
} }
......
...@@ -29,4 +29,4 @@ ...@@ -29,4 +29,4 @@
*/ */
void VB64_init(void); void VB64_init(void);
int VB64_decode(char *d, unsigned dlen, const char *s); int VB64_decode(char *d, unsigned dlen, const char *s, const char *e);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment