diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2004-09-10 23:16:00 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2004-09-10 23:16:00 +0000 |
commit | cf866e0109fae335b6d5d137b2370baabc7fa318 (patch) | |
tree | d5da1055f781a8a7c6c54eaaeb30a476867caa4a /epan/base64.c | |
parent | 808b9e611c01c0ddb46bc25c7ac79907c91ec3ed (diff) |
Move the base-64 routines to "epan/base64.c".
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@11960 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/base64.c')
-rw-r--r-- | epan/base64.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/epan/base64.c b/epan/base64.c new file mode 100644 index 0000000000..48456e3728 --- /dev/null +++ b/epan/base64.c @@ -0,0 +1,62 @@ +/* base64.c + * Base-64 conversion + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <string.h> + +/* Decode a base64 string in-place - simple and slow algorithm. + Return length of result. Taken from rproxy/librsync/base64.c by + Andrew Tridgell. */ + +size_t epan_base64_decode(char *s) +{ + static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int bit_offset, byte_offset, idx, i, n; + unsigned char *d = (unsigned char *)s; + char *p; + + n=i=0; + + while (*s && (p=strchr(b64, *s))) { + idx = (int)(p - b64); + byte_offset = (i*6)/8; + bit_offset = (i*6)%8; + d[byte_offset] &= ~((1<<(8-bit_offset))-1); + if (bit_offset < 3) { + d[byte_offset] |= (idx << (2-bit_offset)); + n = byte_offset+1; + } else { + d[byte_offset] |= (idx >> (bit_offset-2)); + d[byte_offset+1] = 0; + d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; + n = byte_offset+2; + } + s++; i++; + } + + return n; +} |