]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/pkey_meth_test.c
threads_pthread.c: change inline to ossl_inline
[thirdparty/openssl.git] / test / pkey_meth_test.c
CommitLineData
52fe14e6 1/*
0f84cbc3 2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
52fe14e6 3 *
909f1a2e 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
52fe14e6
DSH
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
8 */
9
10/* Internal tests for EVP_PKEY method ordering */
11
41bbba53
P
12/* We need to use some deprecated APIs */
13#define OPENSSL_SUPPRESS_DEPRECATED
14
52fe14e6
DSH
15#include <stdio.h>
16#include <string.h>
17
18#include <openssl/evp.h>
19#include "testutil.h"
52fe14e6 20
48ed9c23
DSH
21/* Test of EVP_PKEY_ASN1_METHOD ordering */
22static int test_asn1_meths(void)
52fe14e6
DSH
23{
24 int i;
25 int prev = -1;
26 int good = 1;
27 int pkey_id;
28 const EVP_PKEY_ASN1_METHOD *ameth;
29
30 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
31 ameth = EVP_PKEY_asn1_get0(i);
32 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
33 if (pkey_id < prev)
34 good = 0;
35 prev = pkey_id;
36
37 }
38 if (!good) {
2fae041d 39 TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
52fe14e6
DSH
40 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
41 const char *info;
42
43 ameth = EVP_PKEY_asn1_get0(i);
44 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
45 if (info == NULL)
46 info = "<NO NAME>";
8fe3127c 47 TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
52fe14e6 48 }
52fe14e6 49 }
52fe14e6
DSH
50 return good;
51}
52
41bbba53 53#ifndef OPENSSL_NO_DEPRECATED_3_0
48ed9c23 54/* Test of EVP_PKEY_METHOD ordering */
31a80694 55static int test_pkey_meths(void)
48ed9c23
DSH
56{
57 size_t i;
58 int prev = -1;
59 int good = 1;
60 int pkey_id;
61 const EVP_PKEY_METHOD *pmeth;
62
63 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
64 pmeth = EVP_PKEY_meth_get0(i);
65 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
66 if (pkey_id < prev)
67 good = 0;
68 prev = pkey_id;
69
70 }
71 if (!good) {
72 TEST_error("EVP_PKEY_METHOD table out of order");
73 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
74 pmeth = EVP_PKEY_meth_get0(i);
75 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
76 TEST_note("%d : %s", pkey_id, OBJ_nid2ln(pkey_id));
77 }
78 }
79 return good;
80}
41bbba53 81#endif
48ed9c23 82
3cb7c5cf 83int setup_tests(void)
52fe14e6
DSH
84{
85 ADD_TEST(test_asn1_meths);
41bbba53 86#ifndef OPENSSL_NO_DEPRECATED_3_0
48ed9c23 87 ADD_TEST(test_pkey_meths);
41bbba53 88#endif
ad887416 89 return 1;
52fe14e6 90}