From 7b7aa016df35ed7f8388a9df08d66a816adc1bf7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Jan 2016 21:53:23 +0100 Subject: [PATCH] asn1: Add asn1_extract_blob() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/asn1.c | 20 ++++++++++++++++++++ lib/util/asn1.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/lib/util/asn1.c b/lib/util/asn1.c index f17cb474dce..a869f6d56d1 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -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 */ diff --git a/lib/util/asn1.h b/lib/util/asn1.h index 94f14f83890..5c2daadb01a 100644 --- a/lib/util/asn1.h +++ b/lib/util/asn1.h @@ -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); -- 2.34.1