summaryrefslogtreecommitdiff
path: root/lib/privkey.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-07-25 12:01:52 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-08-03 11:57:52 +0200
commit2b9280383710838fcfd61bcee13a7725b7cd08b1 (patch)
tree99259a5f16cedcc7a2c0572457bd9636feb9dfed /lib/privkey.c
parent0a479073ba2b34368440f3c977391a7602df1b56 (diff)
downloadgnutls-2b9280383710838fcfd61bcee13a7725b7cd08b1.tar.gz
abstract.h: added functions to read and write SPKI information
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/privkey.c')
-rw-r--r--lib/privkey.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/privkey.c b/lib/privkey.c
index 13d7c53f03..f2ed3313d8 100644
--- a/lib/privkey.c
+++ b/lib/privkey.c
@@ -1610,3 +1610,55 @@ _gnutls_privkey_get_preferred_sign_algo(gnutls_privkey_t key)
}
return GNUTLS_SIGN_UNKNOWN;
}
+
+/**
+ * gnutls_privkey_get_spki:
+ * @privkey: a public key of type #gnutls_privkey_t
+ * @spki: a SubjectPublicKeyInfo structure of type #gnutls_privkey_spki_t
+ * @flags: must be zero
+ *
+ * This function will return the public key information if available.
+ * The provided @spki must be initialized.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ * negative error value.
+ *
+ * Since: 3.6.0
+ **/
+int
+gnutls_privkey_get_spki(gnutls_privkey_t privkey, gnutls_x509_spki_t spki, unsigned int flags)
+{
+ if (privkey == NULL || privkey->type != GNUTLS_PRIVKEY_X509) {
+ gnutls_assert();
+ return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
+ }
+
+ memcpy(spki, &privkey->key.x509->params.spki, sizeof(gnutls_x509_spki_st));
+
+ return 0;
+}
+
+/**
+ * gnutls_privkey_set_spki:
+ * @privkey: a public key of type #gnutls_privkey_t
+ * @spki: a SubjectPublicKeyInfo structure of type #gnutls_privkey_spki_t
+ * @flags: must be zero
+ *
+ * This function will set the public key information.
+ * The provided @spki must be initialized.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ * negative error value.
+ *
+ * Since: 3.6.0
+ **/
+int
+gnutls_privkey_set_spki(gnutls_privkey_t privkey, const gnutls_x509_spki_t spki, unsigned int flags)
+{
+ if (privkey == NULL || privkey->type != GNUTLS_PRIVKEY_X509) {
+ gnutls_assert();
+ return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
+ }
+
+ return gnutls_x509_privkey_set_spki(privkey->key.x509, spki, flags);
+}