asn1: Add asn1_extract_blob()
authorVolker Lendecke <vl@samba.org>
Mon, 4 Jan 2016 20:53:23 +0000 (21:53 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 5 Jan 2016 23:54:18 +0000 (00:54 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/asn1.c
lib/util/asn1.h

index f17cb474dce82b11ac9907f34288c7ebc76e4b1c..a869f6d56d10900cd9e6e9587199c298900955c2 100644 (file)
@@ -1018,6 +1018,26 @@ bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob)
        return true;
 }
 
+bool asn1_extract_blob(struct asn1_data *asn1, TALLOC_CTX *mem_ctx,
+                      DATA_BLOB *pblob)
+{
+       DATA_BLOB blob;
+
+       if (!asn1_blob(asn1, &blob)) {
+               return false;
+       }
+
+       *pblob = (DATA_BLOB) { .length = blob.length };
+       pblob->data = talloc_move(mem_ctx, &blob.data);
+
+       /*
+        * Stop access from here on
+        */
+       asn1->has_error = true;
+
+       return true;
+}
+
 /*
   Fill in an asn1 struct without making a copy
 */
index 94f14f838906d031c87f6e8f09a71cb16176c6b5..5c2daadb01a21c56c910e21247432f468f06d587 100644 (file)
@@ -97,6 +97,8 @@ bool asn1_read_enumerated(struct asn1_data *data, int *v);
 bool asn1_check_enumerated(struct asn1_data *data, int v);
 bool asn1_write_enumerated(struct asn1_data *data, uint8_t v);
 bool asn1_blob(const struct asn1_data *asn1, DATA_BLOB *blob);
+bool asn1_extract_blob(struct asn1_data *asn1, TALLOC_CTX *mem_ctx,
+                      DATA_BLOB *pblob);
 void asn1_load_nocopy(struct asn1_data *data, uint8_t *buf, size_t len);
 int asn1_peek_full_tag(DATA_BLOB blob, uint8_t tag, size_t *packet_size);