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
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>
18 #include <openssl/dh.h>
19 #include <openssl/dsa.h>
20 #include <openssl/rsa.h>
24 static const char *datadir;
26 static BIO *getfile(const char *filename)
28 char *paramsfile = test_mk_file_path(datadir, filename);
31 if (!TEST_ptr(paramsfile))
33 infile = BIO_new_file(paramsfile, "r");
36 OPENSSL_free(paramsfile);
41 static int test_read_dh_params(void)
44 BIO *infile = getfile("dhparams.pem");
47 if (!TEST_ptr(infile))
50 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
62 static int test_read_dh_x942_params(void)
65 BIO *infile = getfile("x942params.pem");
68 if (!TEST_ptr(infile))
71 dh = PEM_read_bio_DHparams(infile, NULL, NULL, NULL);
84 #ifndef OPENSSL_NO_DSA
85 static int test_read_dsa_params(void)
88 BIO *infile = getfile("dsaparams.pem");
91 if (!TEST_ptr(infile))
94 dsa = PEM_read_bio_DSAparams(infile, NULL, NULL, NULL);
106 static int test_read_dsa_private(void)
109 BIO *infile = getfile("dsaprivatekey.pem");
112 if (!TEST_ptr(infile))
115 dsa = PEM_read_bio_DSAPrivateKey(infile, NULL, NULL, NULL);
127 static int test_read_dsa_public(void)
130 BIO *infile = getfile("dsapublickey.pem");
133 if (!TEST_ptr(infile))
136 dsa = PEM_read_bio_DSA_PUBKEY(infile, NULL, NULL, NULL);
149 static int test_read_rsa_private(void)
152 BIO *infile = getfile("rsaprivatekey.pem");
155 if (!TEST_ptr(infile))
158 rsa = PEM_read_bio_RSAPrivateKey(infile, NULL, NULL, NULL);
170 static int test_read_rsa_public(void)
173 BIO *infile = getfile("rsapublickey.pem");
176 if (!TEST_ptr(infile))
179 rsa = PEM_read_bio_RSA_PUBKEY(infile, NULL, NULL, NULL);
191 int setup_tests(void)
193 if (!test_skip_common_options()) {
194 TEST_error("Error parsing test options\n");
198 if (!TEST_ptr(datadir = test_get_argument(0))) {
199 TEST_error("Error getting data dir\n");
203 #ifndef OPENSSL_NO_DH
204 ADD_TEST(test_read_dh_params);
205 ADD_TEST(test_read_dh_x942_params);
207 #ifndef OPENSSL_NO_DSA
208 ADD_TEST(test_read_dsa_params);
209 ADD_TEST(test_read_dsa_private);
210 ADD_TEST(test_read_dsa_public);
212 ADD_TEST(test_read_rsa_private);
213 ADD_TEST(test_read_rsa_public);