aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2003-05-23 05:25:19 +0000
committerTim Potter <tpot@samba.org>2003-05-23 05:25:19 +0000
commitd3913cfdb13d3489f1e212b22a6e44cd9c24fd25 (patch)
tree4491d5f748fd8e189741ff86be146c25f85b4f4e /util.c
parent07ab324c4e6179924e59bbc3437494f74df198d3 (diff)
Move the base64_decode() function somewhere where other dissectors can
use it. svn path=/trunk/; revision=7723
Diffstat (limited to 'util.c')
-rw-r--r--util.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/util.c b/util.c
index ef401dc15f..b7edb4a61c 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.60 2003/03/12 00:07:32 guy Exp $
+ * $Id: util.c,v 1.61 2003/05/23 05:25:18 tpot Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -587,3 +587,36 @@ compute_timestamp_diff(gint *diffsec, gint *diffusec,
}
}
}
+
+/* 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 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;
+}