summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-07 09:37:10 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-07 10:55:17 +0200
commitfa86fc6892d6551340f24da6a6af4f484a62b884 (patch)
tree0182b06c7393d89970b3830f5e4ec7601a6ecff7
parent295328b25b1b7114779cb7c919bf9ab669f1ba34 (diff)
downloadgnutls-fa86fc6892d6551340f24da6a6af4f484a62b884.tar.gz
gnutls_pem_base64_decode: allow decoding raw base64 data
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/x509_b64.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/x509_b64.c b/lib/x509_b64.c
index e5a741a868..49b25e2c97 100644
--- a/lib/x509_b64.c
+++ b/lib/x509_b64.c
@@ -302,12 +302,19 @@ _gnutls_fbase64_decode(const char *header, const uint8_t * data,
int rdata_size;
char pem_header[128];
+ if (header == NULL) {
+ if ((ret = _gnutls_base64_decode(data, data_size, result)) < 0) {
+ gnutls_assert();
+ return GNUTLS_E_BASE64_DECODING_ERROR;
+ }
+ return 0;
+ }
+
_gnutls_str_cpy(pem_header, sizeof(pem_header), top);
if (header != NULL)
_gnutls_str_cat(pem_header, sizeof(pem_header), header);
rdata = memmem(data, data_size, pem_header, strlen(pem_header));
-
if (rdata == NULL) {
gnutls_assert();
_gnutls_hard_log("Could not find '%s'\n", pem_header);
@@ -372,6 +379,10 @@ _gnutls_fbase64_decode(const char *header, const uint8_t * data,
* and decode only this part. Otherwise it will decode the first PEM
* packet found.
*
+ * To decode data from any arbitrary header set the null string as header.
+ * Since 3.6.0 this function will decode arbitrary base64 without any
+ * headers when %NULL is given as header.
+ *
* Returns: On success %GNUTLS_E_SUCCESS (0) is returned,
* %GNUTLS_E_SHORT_MEMORY_BUFFER is returned if the buffer given is
* not long enough, or 0 on success.
@@ -421,6 +432,10 @@ gnutls_pem_base64_decode(const char *header,
* under the name gnutls_pem_base64_decode_alloc(). There is
* compatibility macro pointing to this function.
*
+ * To decode data from any arbitrary header set the null string as header.
+ * Since 3.6.0 this function will decode arbitrary base64 without any
+ * headers when %NULL is given as header.
+ *
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
*