summaryrefslogtreecommitdiff
path: root/lib/str.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-02-22 11:06:51 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-02-23 10:24:44 +0100
commitec60a3daa051603b0be5e1ba7a8484fb5fe7f42a (patch)
tree9a5d41742d915350d00e8eee00e9c7d0903c695d /lib/str.c
parente6badc35efdc6078ca30edb0ee5e059f8da7a305 (diff)
downloadgnutls-ec60a3daa051603b0be5e1ba7a8484fb5fe7f42a.tar.gz
x509/output: print the public key PIN of a certificate
That is, print the value used by the HPKP protocol as per RFC7469. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/str.c')
-rw-r--r--lib/str.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/str.c b/lib/str.c
index 647b03c836..673caa9e7d 100644
--- a/lib/str.c
+++ b/lib/str.c
@@ -27,6 +27,7 @@
#include <stdarg.h>
#include <c-ctype.h>
#include <intprops.h>
+#include <nettle/base64.h>
#include "vasprintf.h"
#include "extras/hex.h"
@@ -918,6 +919,26 @@ _gnutls_buffer_hexprint(gnutls_buffer_st * str,
}
}
+int
+_gnutls_buffer_base64print(gnutls_buffer_st * str,
+ const void *_data, size_t len)
+{
+ const unsigned char *data = _data;
+ unsigned b64len = BASE64_ENCODE_RAW_LENGTH(len);
+ int ret;
+
+ ret = _gnutls_buffer_resize(str, str->length+b64len+1);
+ if (ret < 0) {
+ return gnutls_assert_val(ret);
+ }
+
+ base64_encode_raw(&str->data[str->length], len, data);
+ str->length += b64len;
+ str->data[str->length] = 0;
+
+ return 0;
+}
+
void
_gnutls_buffer_hexdump(gnutls_buffer_st * str, const void *_data,
size_t len, const char *spc)