summaryrefslogtreecommitdiff
path: root/guile/src/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'guile/src/core.c')
-rw-r--r--guile/src/core.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/guile/src/core.c b/guile/src/core.c
index 0926dc8a97..b1dad0777f 100644
--- a/guile/src/core.c
+++ b/guile/src/core.c
@@ -50,6 +50,9 @@
? alloca (size) \
: scm_gc_malloc_pointerless ((size), "gnutls-alloc"))
+/* Maximum size, in bytes, of the hash data returned by a digest algorithm. */
+#define MAX_HASH_SIZE 64
+
/* SMOB and enums type definitions. */
#include "enum-map.i.c"
#include "smob-types.i.c"
@@ -2891,6 +2894,40 @@ SCM_DEFINE (scm_gnutls_x509_certificate_subject_alternative_name,
}
#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_x509_certificate_fingerprint,
+ "x509-certificate-fingerprint",
+ 2, 0, 0,
+ (SCM cert, SCM algo),
+ "Return the fingerprint (a u8vector) of the certificate "
+ "@var{cert}, computed using the digest algorithm @var{algo}.")
+#define FUNC_NAME s_scm_gnutls_x509_certificate_fingerprint
+{
+ int err;
+ SCM result;
+ gnutls_x509_crt_t c_cert;
+ gnutls_digest_algorithm_t c_algo;
+ uint8_t c_fpr[MAX_HASH_SIZE];
+ size_t c_fpr_len = MAX_HASH_SIZE;
+ scm_t_array_handle c_handle;
+
+ c_cert = scm_to_gnutls_x509_certificate (cert, 1, FUNC_NAME);
+ c_algo = scm_to_gnutls_digest (algo, 1, FUNC_NAME);
+
+ err = gnutls_x509_crt_get_fingerprint (c_cert, c_algo, &c_fpr, &c_fpr_len);
+ if (EXPECT_FALSE (err))
+ scm_gnutls_error (err, FUNC_NAME);
+
+ result = scm_make_u8vector (scm_from_uint(c_fpr_len), SCM_INUM0);
+ scm_array_get_handle (result, &c_handle);
+ memcpy (scm_array_handle_u8_writable_elements (&c_handle), &c_fpr,
+ c_fpr_len);
+ scm_array_handle_release (&c_handle);
+
+ return result;
+}
+
+#undef FUNC_NAME
/* OpenPGP keys. */