asn1: Add asn1_extract_blob()
[obnox/samba/samba-obnox.git] / lib / util / asn1.c
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
 */