Add a generic SubjectPublicKeyInfo decoder
[openssl.git] / providers / implementations / encode_decode / endecoder_common.c
index c85fe915ac4dfd31171e0c9025476f96b0876ded..7d26e2a34051083b9b0ea90558b87f7bcbd5cc31 100644 (file)
@@ -8,7 +8,9 @@
  */
 
 #include <openssl/core.h>
-
+#include <openssl/buffer.h>
+#include "internal/asn1.h"
+#include "prov/bio.h"
 #include "endecoder_local.h"
 
 OSSL_FUNC_keymgmt_new_fn *
@@ -82,3 +84,18 @@ void ossl_prov_free_key(const OSSL_DISPATCH *fns, void *key)
         kmgmt_free(key);
 }
 
+int ossl_read_der(PROV_CTX *provctx, OSSL_CORE_BIO *cin,  unsigned char **data,
+                  long *len)
+{
+    BUF_MEM *mem = NULL;
+    BIO *in = ossl_bio_new_from_core_bio(provctx, cin);
+    int ok = (asn1_d2i_read_bio(in, &mem) >= 0);
+
+    if (ok) {
+        *data = (unsigned char *)mem->data;
+        *len = (long)mem->length;
+        OPENSSL_free(mem);
+    }
+    BIO_free(in);
+    return ok;
+}