2 * Copyright 2020 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
11 * This file tests deprecated APIs. Therefore we need to suppress deprecation
14 #define OPENSSL_SUPPRESS_DEPRECATED
16 #include <openssl/pem.h>
17 #include <openssl/bio.h>
21 static const char *datadir;
23 static BIO *getfile(const char *filename)
25 char *paramsfile = test_mk_file_path(datadir, filename);
28 if (!TEST_ptr(paramsfile))
30 infile = BIO_new_file(paramsfile, "r");
33 OPENSSL_free(paramsfile);
38 static int test_read_dh_params(void)
41 BIO *infile = getfile("dhparams.pem");
44 if (!TEST_ptr(infile))
47 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
59 static int test_read_dh_x942_params(void)
62 BIO *infile = getfile("x942params.pem");
65 if (!TEST_ptr(infile))
68 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
81 #ifndef OPENSSL_NO_DSA
82 static int test_read_dsa_params(void)
85 BIO *infile = getfile("dsaparams.pem");
88 if (!TEST_ptr(infile))
91 dsa = PEM_read_bio_DSAparams(infile, NULL, NULL, NULL);
103 static int test_read_dsa_private(void)
106 BIO *infile = getfile("dsaprivatekey.pem");
109 if (!TEST_ptr(infile))
112 dsa = PEM_read_bio_DSAPrivateKey(infile, NULL, NULL, NULL);
124 static int test_read_dsa_public(void)
127 BIO *infile = getfile("dsapublickey.pem");
130 if (!TEST_ptr(infile))
133 dsa = PEM_read_bio_DSA_PUBKEY(infile, NULL, NULL, NULL);
146 static int test_read_rsa_private(void)
149 BIO *infile = getfile("rsaprivatekey.pem");
152 if (!TEST_ptr(infile))
155 rsa = PEM_read_bio_RSAPrivateKey(infile, NULL, NULL, NULL);
167 static int test_read_rsa_public(void)
170 BIO *infile = getfile("rsapublickey.pem");
173 if (!TEST_ptr(infile))
176 rsa = PEM_read_bio_RSA_PUBKEY(infile, NULL, NULL, NULL);
188 int setup_tests(void)
190 if (!test_skip_common_options()) {
191 TEST_error("Error parsing test options\n");
195 if (!TEST_ptr(datadir = test_get_argument(0))) {
196 TEST_error("Error getting data dir\n");
200 #ifndef OPENSSL_NO_DH
201 ADD_TEST(test_read_dh_params);
202 ADD_TEST(test_read_dh_x942_params);
204 #ifndef OPENSSL_NO_DSA
205 ADD_TEST(test_read_dsa_params);
206 ADD_TEST(test_read_dsa_private);
207 ADD_TEST(test_read_dsa_public);
209 ADD_TEST(test_read_rsa_private);
210 ADD_TEST(test_read_rsa_public);