From: wessels <> Date: Tue, 16 Jul 1996 06:03:01 +0000 (+0000) Subject: By Henrik for FTP auth stuff X-Git-Tag: SQUID_3_0_PRE1~6054 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c05d982e3c1aa51dea048e8cfcc5d3490b6c740;p=thirdparty%2Fsquid.git By Henrik for FTP auth stuff --- diff --git a/lib/base64.c b/lib/base64.c new file mode 100644 index 0000000000..7ac882bfd7 --- /dev/null +++ b/lib/base64.c @@ -0,0 +1,60 @@ +#include "config.h" + +#if HAVE_STDIO_H +#include +#endif +#if HAVE_STDLIB_H +#include +#endif + +static int base64_initialized = 0; +int base64_value[256]; +char base64_code[] = "ABCDEFGHIJKLMNOPQRSTUVWZYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static void base64_init() +{ + int i; + + for (i = 0; i < 256; i++) + base64_value[i] = -1; + + for (i = 0; i < 64; i++) + base64_value[(int) base64_code[i]] = i; + base64_value['='] = 0; + + base64_initialized = 1; +} + +char *base64_decode(p) + unsigned char *p; +{ + static char result[8192]; + int c; + long val; + int i; + char *d; + + if (!p) + return p; + + if (!base64_initialized) + base64_init(); + + val = c = 0; + d = result; + while (*p) { + i = base64_value[(int) *p++]; + if (i >= 0) { + val = val * 64 + i; + c++; + } + if (c == 4) { /* One quantum of four encoding characters/24 bit */ + *d++ = val >> 16; /* High 8 bits */ + *d++ = (val >> 8) & 0xff; /* Mid 8 bits */ + *d++ = val & 0xff; /* Low 8 bits */ + val = c = 0; + } + } + + return *result ? result : NULL; +}