summaryrefslogtreecommitdiff
path: root/libextra/openpgp
diff options
context:
space:
mode:
authorTimo Schulz <twoaday@gnutls.org>2007-05-14 08:45:18 +0000
committerTimo Schulz <twoaday@gnutls.org>2007-05-14 08:45:18 +0000
commit473866f9a2fb985e2689e909c1ca7d0688228a2c (patch)
treec1ea862fd61110808b6980a4558846578a567c48 /libextra/openpgp
parent72f5cd0f1c977e99e69101f293cdc7286bc46947 (diff)
downloadgnutls-473866f9a2fb985e2689e909c1ca7d0688228a2c.tar.gz
patch to support raw keyrings.
Diffstat (limited to 'libextra/openpgp')
-rw-r--r--libextra/openpgp/extras.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/libextra/openpgp/extras.c b/libextra/openpgp/extras.c
index 9952c05311..4eca072d97 100644
--- a/libextra/openpgp/extras.c
+++ b/libextra/openpgp/extras.c
@@ -110,13 +110,14 @@ gnutls_openpgp_keyring_check_id (gnutls_openpgp_keyring_t ring,
}
/**
- * gnutls_openpgp_keyring_import - This function will import a RAW or BASE64 encoded key
+ * gnutls_openpgp_keyring_import - Import a raw- or Base64-encoded OpenPGP keyring
* @keyring: The structure to store the parsed key.
* @data: The RAW or BASE64 encoded keyring.
- * @format: One of gnutls_openpgp_keyring_fmt elements.
+ * @format: One of #gnutls_openpgp_keyring_fmt elements.
*
- * This function will convert the given RAW or Base64 encoded keyring
- * to the native gnutls_openpgp_keyring_t format. The output will be stored in 'keyring'.
+ * This function will convert the given RAW or Base64 encoded keyring to the
+ * native #gnutls_openpgp_keyring_t format. The output will be stored in
+ * 'keyring'.
*
* Returns 0 on success.
*
@@ -126,30 +127,33 @@ gnutls_openpgp_keyring_import (gnutls_openpgp_keyring_t keyring,
const gnutls_datum_t *data,
gnutls_openpgp_key_fmt_t format)
{
- int rc;
- keybox_blob *blob = NULL;
-
+ cdk_error_t err;
- blob = kbx_read_blob (data, 0);
- if (!blob)
+ if (format == GNUTLS_OPENPGP_FMT_RAW)
{
- gnutls_assert ();
- return GNUTLS_E_OPENPGP_KEYRING_ERROR;
+ err = cdk_keydb_new (&keyring->db, CDK_DBTYPE_DATA,
+ data->data, data->size);
+ if (err)
+ {
+ gnutls_assert ();
+ return _gnutls_map_cdk_rc (err);
+ }
}
-
- keyring->db = kbx_to_keydb (blob);
- if (!keyring->db)
+ else
{
- gnutls_assert ();
- rc = GNUTLS_E_OPENPGP_KEYRING_ERROR;
- goto leave;
+ cdk_stream_t input;
+
+ err = cdk_stream_tmp_from_mem (data->data, data->size, &input);
+ if (!err)
+ err = cdk_stream_set_armor_flag (input, 0);
+ if (!err)
+ err = cdk_keydb_new_from_stream (&keyring->db, 0, input);
+ cdk_stream_close (input);
}
-
- rc = 0;
-
-leave:
- kbx_blob_release (blob);
- return rc;
+
+ if (err)
+ gnutls_assert ();
+ return _gnutls_map_cdk_rc (err);
}