summaryrefslogtreecommitdiff
path: root/trust/asn1.c
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-04 15:37:34 +0200
committerStef Walter <stef@thewalter.net>2013-07-04 15:42:16 +0200
commitec7c2ff2011d774217c1e35d664072d0487853c7 (patch)
treec2ff76fc08c9b237f101d4119451ef04229c7788 /trust/asn1.c
parenta2165fe35e336fd807af053a21a396b020f90a23 (diff)
downloadp11-kit-ec7c2ff2011d774217c1e35d664072d0487853c7.tar.gz
trust: Add p11_asn1_read() and p11_asn1_free() functions
Some helpers for commonly used ASN.1 related stuff.
Diffstat (limited to 'trust/asn1.c')
-rw-r--r--trust/asn1.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/trust/asn1.c b/trust/asn1.c
index 29cca3a..fcd8e1c 100644
--- a/trust/asn1.c
+++ b/trust/asn1.c
@@ -192,6 +192,44 @@ p11_asn1_encode (node_asn *asn,
return der;
}
+void *
+p11_asn1_read (node_asn *asn,
+ const char *field,
+ size_t *length)
+{
+ void *value;
+ int len;
+ int ret;
+
+ return_val_if_fail (asn != NULL, NULL);
+ return_val_if_fail (field != NULL, NULL);
+ return_val_if_fail (length != NULL, NULL);
+
+ len = 0;
+ ret = asn1_read_value (asn, field, NULL, &len);
+ if (ret == ASN1_ELEMENT_NOT_FOUND)
+ return NULL;
+
+ return_val_if_fail (ret == ASN1_MEM_ERROR, NULL);
+
+ value = malloc (len);
+ return_val_if_fail (value != NULL, NULL);
+
+ ret = asn1_read_value (asn, field, value, &len);
+ return_val_if_fail (ret == ASN1_SUCCESS, NULL);
+
+ *length = len;
+ return value;
+}
+
+void
+p11_asn1_free (void *asn)
+{
+ node_asn *node = asn;
+ if (node != NULL)
+ asn1_delete_structure (&node);
+}
+
ssize_t
p11_asn1_tlv_length (const unsigned char *data,
size_t length)