aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authortpot <tpot@f5534014-38df-0310-8fa8-9805f1628bb7>2003-05-23 05:25:19 +0000
committertpot <tpot@f5534014-38df-0310-8fa8-9805f1628bb7>2003-05-23 05:25:19 +0000
commit6af523324db85c378a1ceceddec98ec0fe986691 (patch)
tree4491d5f748fd8e189741ff86be146c25f85b4f4e /util.c
parentb59a570d2a768b9ed340572fb85d495833777e6a (diff)
Move the base64_decode() function somewhere where other dissectors can
use it. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@7723 f5534014-38df-0310-8fa8-9805f1628bb7
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;
+}