summaryrefslogtreecommitdiff
path: root/lib/x509/dn.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-03-05 15:55:09 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-03-05 15:58:48 +0100
commit1b31dc9a2dfe8dbe3a4c1f9e30900e0a0efcfda3 (patch)
treea59ac0fcbd39870fdc83c1dc43d39de2c5007d66 /lib/x509/dn.c
parente7056d36d764204e744463f3f25b9c7c63ee8870 (diff)
downloadgnutls-1b31dc9a2dfe8dbe3a4c1f9e30900e0a0efcfda3.tar.gz
Added new functions to get the LDAP DN in an allocated buffer.
Diffstat (limited to 'lib/x509/dn.c')
-rw-r--r--lib/x509/dn.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/x509/dn.c b/lib/x509/dn.c
index 3ecdc72ad7..99d41ffcc5 100644
--- a/lib/x509/dn.c
+++ b/lib/x509/dn.c
@@ -84,6 +84,44 @@ cleanup:
return ret;
}
+int
+_gnutls_x509_get_dn (ASN1_TYPE asn1_struct,
+ const char *asn1_rdn_name, gnutls_datum_t * dn)
+{
+char * buf;
+size_t buf_size;
+int ret;
+
+ buf_size = 384;
+ buf = gnutls_malloc(buf_size);
+ if (buf == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ ret = _gnutls_x509_parse_dn (asn1_struct,
+ asn1_rdn_name, buf, &buf_size);
+ if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
+ {
+ buf = gnutls_realloc_fast(buf, buf_size);
+ if (buf == NULL)
+ return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+ ret = _gnutls_x509_parse_dn (asn1_struct,
+ asn1_rdn_name, buf, &buf_size);
+ }
+
+ if (ret < 0)
+ {
+ gnutls_free(buf);
+ return gnutls_assert_val(ret);
+ }
+
+ dn->data = (void*)buf;
+ dn->size = buf_size;
+
+ return ret;
+}
+
+
/* Parses an X509 DN in the asn1_struct, and puts the output into
* the string buf. The output is an LDAP encoded DN.
*