Fix build by #if 0 out unused de_sgsap_tmsi() function.
[obnox/wireshark/wip.git] / epan / base64.c
index b390947f3518d888dd67be7c57f7db6e638afe8d..949e995c0afa38f3fd0793bc6e75edf4af10b2e9 100644 (file)
 size_t epan_base64_decode(char *s)
 {
        static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
-       int bit_offset, byte_offset, idx, i, n;
+       int bit_offset, byte_offset, idx, i;
        unsigned char *d = (unsigned char *)s;
        char *p;
        int  cr_idx;
 
        /* we will allow CR and LF - but ignore them */
-       cr_idx = strchr(b64, '\r') - b64;
+       cr_idx = (int) (strchr(b64, '\r') - b64);
 
-       n=i=0;
+       i=0;
 
        while (*s && (p=strchr(b64, *s))) {
                idx = (int)(p - b64);
@@ -54,17 +54,33 @@ size_t epan_base64_decode(char *s)
                        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;
                        }
                        i++;
                }
                s++; 
        }
 
-       return n;
+       return i*3/4;
+}
+
+/* Return a tvb that contains the binary representation of a base64
+   string */
+
+tvbuff_t *
+base64_to_tvb(tvbuff_t *parent, const char *base64)
+{
+  tvbuff_t *tvb;
+  char *data = g_strdup(base64);
+  gint len;
+
+  len = (gint) epan_base64_decode(data);
+  tvb = tvb_new_child_real_data(parent, (const guint8 *)data, len, len);
+
+  tvb_set_free_cb(tvb, g_free);
+
+  return tvb;
 }