summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2006-03-08 16:24:51 +0000
committerSimon Josefsson <simon@josefsson.org>2006-03-08 16:24:51 +0000
commitc94f599e8a1a358a7de28e0784fbcd9b1e9c9929 (patch)
tree246cd584909a1570b0cf7d01f66232d8a45cf6a7 /lib
parentd9f65cdc1155815097e18bd0ff094393bc610636 (diff)
downloadlibtasn1-c94f599e8a1a358a7de28e0784fbcd9b1e9c9929.tar.gz
libtasn1-c94f599e8a1a358a7de28e0784fbcd9b1e9c9929.tar.bz2
libtasn1-c94f599e8a1a358a7de28e0784fbcd9b1e9c9929.zip
Add, from GnuTLS.
Diffstat (limited to 'lib')
-rw-r--r--lib/structure.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/structure.c b/lib/structure.c
index 3eaf338..32c4663 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -967,3 +967,53 @@ asn1_find_structure_from_oid (ASN1_TYPE definitions,
return NULL; /* ASN1_ELEMENT_NOT_FOUND; */
}
+
+/**
+ * asn1_copy_node:
+ * @dst: Destination ASN1_TYPE node.
+ * @dst_name: Field name in destination node.
+ * @src: Source ASN1_TYPE node.
+ * @src_name: Field name in source node.
+ *
+ * Create a deep copy of a ASN1_TYPE variable.
+ *
+ * Return value: Return ASN1_SUCCESS on success.
+ **/
+asn1_retCode
+asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
+ ASN1_TYPE src, const char *src_name)
+{
+
+ int result;
+ ASN1_TYPE dst_node;
+ void *data = NULL;
+ int size = 0;
+
+ result = asn1_der_coding (src, src_name, NULL, &size, NULL);
+ if (result != ASN1_MEM_ERROR)
+ return result;
+
+ data = _asn1_malloc (size);
+ if (data == NULL)
+ return ASN1_MEM_ERROR;
+
+ result = asn1_der_coding (src, src_name, data, &size, NULL);
+ if (result != ASN1_SUCCESS)
+ {
+ _asn1_free (data);
+ return result;
+ }
+
+ dst_node = asn1_find_node (dst, dst_name);
+ if (dst_node == NULL)
+ {
+ _asn1_free (data);
+ return ASN1_ELEMENT_NOT_FOUND;
+ }
+
+ result = asn1_der_decoding (&dst_node, data, size, NULL);
+
+ _asn1_free (data);
+
+ return result;
+}