]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/x509_load_cert_file_test.c
4a736071ae61e57a48838969999755c845914484
[thirdparty/openssl.git] / test / x509_load_cert_file_test.c
1 /*
2 * Licensed under the Apache License 2.0 (the "License"). You may not use
3 * this file except in compliance with the License. You can obtain a copy
4 * in the file LICENSE in the source distribution or at
5 * https://www.openssl.org/source/license.html
6 */
7
8 #include <stdio.h>
9 #include <openssl/err.h>
10 #include <openssl/x509_vfy.h>
11
12 #include "testutil.h"
13
14 static const char *chain;
15
16 static int test_load_cert_file(void)
17 {
18 int ret = 0;
19 X509_STORE *store = NULL;
20 X509_LOOKUP *lookup = NULL;
21 STACK_OF(X509) *certs = NULL;
22
23 if (TEST_ptr(store = X509_STORE_new())
24 && TEST_ptr(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()))
25 && TEST_true(X509_load_cert_file(lookup, chain, X509_FILETYPE_PEM))
26 && TEST_ptr(certs = X509_STORE_get1_all_certs(store))
27 && TEST_int_eq(sk_X509_num(certs), 4))
28 ret = 1;
29
30 OSSL_STACK_OF_X509_free(certs);
31 X509_STORE_free(store);
32 return ret;
33 }
34
35 OPT_TEST_DECLARE_USAGE("cert.pem...\n")
36
37 int setup_tests(void)
38 {
39 if (!test_skip_common_options()) {
40 TEST_error("Error parsing test options\n");
41 return 0;
42 }
43
44 chain = test_get_argument(0);
45 if (chain == NULL)
46 return 0;
47
48 ADD_TEST(test_load_cert_file);
49 return 1;
50 }