]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/testutil/load.c
2 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
13 #include <openssl/x509.h>
14 #include <openssl/pem.h>
16 #include "../testutil.h"
18 X509
*load_cert_pem(const char *file
, OSSL_LIB_CTX
*libctx
)
23 if (!TEST_ptr(file
) || !TEST_ptr(bio
= BIO_new(BIO_s_file())))
25 if (TEST_int_gt(BIO_read_filename(bio
, file
), 0)
26 && TEST_ptr(cert
= X509_new_ex(libctx
, NULL
)))
27 (void)TEST_ptr(cert
= PEM_read_bio_X509(bio
, &cert
, NULL
, NULL
));
33 STACK_OF(X509
) *load_certs_pem(const char *file
)
35 STACK_OF(X509
) *certs
;
39 if (!TEST_ptr(file
) || (bio
= BIO_new_file(file
, "r")) == NULL
)
42 certs
= sk_X509_new_null();
50 x
= PEM_read_bio_X509(bio
, NULL
, 0, NULL
);
51 if (x
!= NULL
&& !sk_X509_push(certs
, x
)) {
52 sk_X509_pop_free(certs
, X509_free
);
55 } else if (x
== NULL
) {
57 * We probably just ran out of certs, so ignore any errors
69 EVP_PKEY
*load_pkey_pem(const char *file
, OSSL_LIB_CTX
*libctx
)
74 if (!TEST_ptr(file
) || !TEST_ptr(bio
= BIO_new(BIO_s_file())))
76 if (TEST_int_gt(BIO_read_filename(bio
, file
), 0))
77 (void)TEST_ptr(key
= PEM_read_bio_PrivateKey_ex(bio
, NULL
, NULL
, NULL
,
84 X509_REQ
*load_csr_der(const char *file
)
89 if (!TEST_ptr(file
) || !TEST_ptr(bio
= BIO_new_file(file
, "rb")))
91 (void)TEST_ptr(csr
= d2i_X509_REQ_bio(bio
, NULL
));