diff common/strhelp.c @ 188:a3bde2aaabd9

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 26 Mar 2014 09:12:10 +0100
parents 4def8b263dd3
children c596568fa45b
line wrap: on
line diff
--- a/common/strhelp.c	Wed Mar 26 09:10:46 2014 +0100
+++ b/common/strhelp.c	Wed Mar 26 09:12:10 2014 +0100
@@ -5,6 +5,8 @@
 #include <string.h>
 #include <assert.h>
 
+#include <polarssl/base64.h>
+
 /* Remarks regarding the "Flawfinder: ignore" comments in this file:
  *
  * - strlen:
@@ -150,3 +152,33 @@
         (*s)[i] = '\0';
     }
 }
+
+int str_base64_decode(char **dst, size_t *dst_size, char *src,
+                      size_t src_size)
+{
+    int ret = -1;
+
+    if (!dst || *dst) {
+        return -1;
+    }
+
+    /* Check the needed size for the buffer */
+    ret = base64_decode(NULL, dst_size,
+                        (unsigned char *)src, src_size);
+
+    if (ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
+        return ret;
+    }
+
+    *dst = xmalloc(*dst_size);
+    memset (*dst, 0, *dst_size);
+
+    ret = base64_decode((unsigned char *)*dst, dst_size,
+                        (unsigned char *)src, src_size);
+    if (ret) {
+        free (*dst);
+        *dst = NULL;
+        *dst_size = 0;
+    }
+    return ret;
+}

http://wald.intevation.org/projects/trustbridge/