summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-09-07 15:28:42 +1000
committerAndrew Tridgell <tridge@samba.org>2011-09-08 03:35:27 +0200
commit6e25723c82eced9eff8c06bd645b754008824370 (patch)
tree9cec25329c3aafe5418ecd423df6ed688bcce8b9 /lib
parent1e9573fe4d6204a0c9b790f290e1a3763e2d980f (diff)
downloadsamba-6e25723c82eced9eff8c06bd645b754008824370.tar.gz
samba-6e25723c82eced9eff8c06bd645b754008824370.tar.bz2
samba-6e25723c82eced9eff8c06bd645b754008824370.zip
lib: added base64_decode_data_blob_talloc()
its nice to be able to allocate on other than NULL Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/base64.c13
-rw-r--r--lib/util/util.h8
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/util/base64.c b/lib/util/base64.c
index 19ce2d1b85..bc78404c18 100644
--- a/lib/util/base64.c
+++ b/lib/util/base64.c
@@ -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,10 +61,19 @@ _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
**/
_PUBLIC_ void base64_decode_inplace(char *s)
diff --git a/lib/util/util.h b/lib/util/util.h
index 0102feaddf..9a76fa9f04 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -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
**/