lib: added base64_decode_data_blob_talloc()
authorAndrew Tridgell <tridge@samba.org>
Wed, 7 Sep 2011 05:28:42 +0000 (15:28 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 8 Sep 2011 01:35:27 +0000 (03:35 +0200)
its nice to be able to allocate on other than NULL

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

lib/util/base64.c
lib/util/util.h

index 19ce2d1b850f23ec38b0e251f1d607cef3d9cbff..bc78404c181324a3d7e1485e75d08149b071f648 100644 (file)
@@ -29,10 +29,10 @@ static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0
 /**
  * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
  **/
-_PUBLIC_ DATA_BLOB base64_decode_data_blob(const char *s)
+_PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const char *s)
 {
        int bit_offset, byte_offset, idx, i, n;
-       DATA_BLOB decoded = data_blob(s, strlen(s)+1);
+       DATA_BLOB decoded = data_blob_talloc(mem_ctx, s, strlen(s)+1);
        unsigned char *d = decoded.data;
        char *p;
 
@@ -61,9 +61,18 @@ _PUBLIC_ DATA_BLOB base64_decode_data_blob(const char *s)
 
        /* fix up length */
        decoded.length = n;
+       decoded.data = talloc_realloc(mem_ctx, decoded.data, uint8_t, n);
        return decoded;
 }
 
+/**
+ * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
+ **/
+_PUBLIC_ DATA_BLOB base64_decode_data_blob(const char *s)
+{
+       return base64_decode_data_blob_talloc(NULL, s);
+}
+
 /**
  * Decode a base64 string in-place - wrapper for the above
  **/
index 0102feaddfe54e9906b3dbe7669929f9101fbe64..9a76fa9f0430f8527078a75dffa80441834d8812 100644 (file)
@@ -412,7 +412,15 @@ _PUBLIC_ void string_replace(char *s, char oldc, char newc);
 /**
  Base64 decode a string, place into a data blob.  Caller to data_blob_free() the result.
 **/
+_PUBLIC_ DATA_BLOB base64_decode_data_blob_talloc(TALLOC_CTX *mem_ctx, const char *s);
+
+/**
+ Base64 decode a string, place into a data blob on NULL context.
+ Caller to data_blob_free() the result.
+**/
 _PUBLIC_ DATA_BLOB base64_decode_data_blob(const char *s);
+
+
 /**
  Base64 decode a string, inplace
 **/