summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-07-27 17:42:33 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-07-27 17:42:33 +0200
commit724bc2f719148f097c9d65f216ab6364abf8fb5f (patch)
treecc2e3d6e01a0ccdaf59e3dd1b106e38f1453f273
parent74062dd6be8373a3a692580aa0e7808a1a2f0624 (diff)
downloadgnutls-724bc2f719148f097c9d65f216ab6364abf8fb5f.tar.gz
Added gnutls_pcert_list_import_x509_raw() and few doc fixes.
-rw-r--r--lib/gnutls_pcert.c64
-rw-r--r--lib/gnutls_privkey.c6
-rw-r--r--lib/includes/gnutls/abstract.h6
-rw-r--r--lib/libgnutls.map1
4 files changed, 74 insertions, 3 deletions
diff --git a/lib/gnutls_pcert.c b/lib/gnutls_pcert.c
index ef360a17ff..1927b90bcf 100644
--- a/lib/gnutls_pcert.c
+++ b/lib/gnutls_pcert.c
@@ -100,6 +100,70 @@ cleanup:
}
/**
+ * gnutls_pcert_list_import_x509_raw:
+ * @pcerts: The structures to store the parsed certificate. Must not be initialized.
+ * @pcert_max: Initially must hold the maximum number of certs. It will be updated with the number of certs available.
+ * @data: The certificates.
+ * @format: One of DER or PEM.
+ * @flags: must be (0) or an OR'd sequence of gnutls_certificate_import_flags.
+ *
+ * This function will convert the given PEM encoded certificate list
+ * to the native gnutls_x509_crt_t format. The output will be stored
+ * in @certs. They will be automatically initialized.
+ *
+ * If the Certificate is PEM encoded it should have a header of "X509
+ * CERTIFICATE", or "CERTIFICATE".
+ *
+ * Returns: the number of certificates read or a negative error value.
+ **/
+int
+gnutls_pcert_list_import_x509_raw (gnutls_pcert_st * pcerts,
+ unsigned int *pcert_max,
+ const gnutls_datum_t * data,
+ gnutls_x509_crt_fmt_t format, unsigned int flags)
+{
+int ret, i = 0, j;
+gnutls_x509_crt_t *crt;
+
+ crt = gnutls_malloc((*pcert_max) * sizeof(gnutls_x509_crt_t));
+
+ if (crt == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ ret = gnutls_x509_crt_list_import( crt, pcert_max, data, format, flags);
+ if (ret < 0)
+ {
+ ret = gnutls_assert_val(ret);
+ goto cleanup;
+ }
+
+ for (i=0;i<*pcert_max;i++)
+ {
+ ret = gnutls_pcert_import_x509(&pcerts[i], crt[i], flags);
+ if (ret < 0)
+ {
+ ret = gnutls_assert_val(ret);
+ goto cleanup_pcert;
+ }
+ }
+
+ ret = 0;
+ goto cleanup;
+
+cleanup_pcert:
+ for (j=0;j<i;j++)
+ gnutls_pcert_deinit(&pcerts[j]);
+
+cleanup:
+ for (i=0;i<*pcert_max;i++)
+ gnutls_x509_crt_deinit(crt[i]);
+
+ gnutls_free(crt);
+ return ret;
+
+}
+
+/**
* gnutls_pcert_import_x509_raw:
* @pcert: The pcert structure
* @cert: The raw certificate to be imported
diff --git a/lib/gnutls_privkey.c b/lib/gnutls_privkey.c
index ef2801a2cb..422b2e1ac8 100644
--- a/lib/gnutls_privkey.c
+++ b/lib/gnutls_privkey.c
@@ -307,7 +307,7 @@ static int check_if_clean(gnutls_privkey_t key)
* gnutls_privkey_import_pkcs11:
* @pkey: The private key
* @key: The private key to be imported
- * @flags: should be zero
+ * @flags: should be zero or %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
*
* This function will import the given private key to the abstract
* #gnutls_privkey_t structure.
@@ -345,7 +345,7 @@ int ret;
* gnutls_privkey_import_x509:
* @pkey: The private key
* @key: The private key to be imported
- * @flags: should be zero
+ * @flags: should be zero or %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
*
* This function will import the given private key to the abstract
* #gnutls_privkey_t structure.
@@ -382,7 +382,7 @@ int ret;
* gnutls_privkey_import_openpgp:
* @pkey: The private key
* @key: The private key to be imported
- * @flags: should be zero
+ * @flags: should be zero or %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE
*
* This function will import the given private key to the abstract
* #gnutls_privkey_t structure.
diff --git a/lib/includes/gnutls/abstract.h b/lib/includes/gnutls/abstract.h
index 078ab60897..c1a028e3ed 100644
--- a/lib/includes/gnutls/abstract.h
+++ b/lib/includes/gnutls/abstract.h
@@ -182,6 +182,12 @@ typedef struct gnutls_pcert_st {
int gnutls_pcert_import_x509 (gnutls_pcert_st* pcert,
gnutls_x509_crt_t crt, unsigned int flags);
+int
+gnutls_pcert_list_import_x509_raw (gnutls_pcert_st * pcerts,
+ unsigned int *pcert_max,
+ const gnutls_datum_t * data,
+ gnutls_x509_crt_fmt_t format, unsigned int flags);
+
int gnutls_pcert_import_x509_raw (gnutls_pcert_st* pcert,
const gnutls_datum_t* cert,
gnutls_x509_crt_fmt_t format, unsigned int flags);
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index b26c06585d..42bb8382bd 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -714,6 +714,7 @@ GNUTLS_3_0_0 {
gnutls_x509_trust_list_verify_named_crt;
gnutls_x509_trust_list_add_named_crt;
gnutls_alert_get_strname;
+ gnutls_pcert_list_import_x509_raw;
} GNUTLS_2_12;
GNUTLS_PRIVATE {