1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdio.h> 11e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 12e1051a39Sopenharmony_ci#include <openssl/buffer.h> 13e1051a39Sopenharmony_ci#include <openssl/objects.h> 14e1051a39Sopenharmony_ci#include <openssl/evp.h> 15e1051a39Sopenharmony_ci#include <openssl/x509.h> 16e1051a39Sopenharmony_ci#include <openssl/pem.h> 17e1051a39Sopenharmony_ci 18e1051a39Sopenharmony_ci/* Handle 'other' PEMs: not private keys */ 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_civoid *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, 21e1051a39Sopenharmony_ci pem_password_cb *cb, void *u) 22e1051a39Sopenharmony_ci{ 23e1051a39Sopenharmony_ci const unsigned char *p = NULL; 24e1051a39Sopenharmony_ci unsigned char *data = NULL; 25e1051a39Sopenharmony_ci long len; 26e1051a39Sopenharmony_ci char *ret = NULL; 27e1051a39Sopenharmony_ci 28e1051a39Sopenharmony_ci if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u)) 29e1051a39Sopenharmony_ci return NULL; 30e1051a39Sopenharmony_ci p = data; 31e1051a39Sopenharmony_ci ret = d2i(x, &p, len); 32e1051a39Sopenharmony_ci if (ret == NULL) 33e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB); 34e1051a39Sopenharmony_ci OPENSSL_free(data); 35e1051a39Sopenharmony_ci return ret; 36e1051a39Sopenharmony_ci} 37