]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/pkey_meth_test.c
Create provider errors and use them
[thirdparty/openssl.git] / test / pkey_meth_test.c
CommitLineData
52fe14e6 1/*
83cf7abf 2 * Copyright 2016-2018 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
12#include <stdio.h>
13#include <string.h>
14
15#include <openssl/evp.h>
16#include "testutil.h"
52fe14e6 17
48ed9c23
DSH
18/* Test of EVP_PKEY_ASN1_METHOD ordering */
19static int test_asn1_meths(void)
52fe14e6
DSH
20{
21 int i;
22 int prev = -1;
23 int good = 1;
24 int pkey_id;
25 const EVP_PKEY_ASN1_METHOD *ameth;
26
27 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
28 ameth = EVP_PKEY_asn1_get0(i);
29 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
30 if (pkey_id < prev)
31 good = 0;
32 prev = pkey_id;
33
34 }
35 if (!good) {
2fae041d 36 TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
52fe14e6
DSH
37 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
38 const char *info;
39
40 ameth = EVP_PKEY_asn1_get0(i);
41 EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
42 if (info == NULL)
43 info = "<NO NAME>";
8fe3127c 44 TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
52fe14e6 45 }
52fe14e6 46 }
52fe14e6
DSH
47 return good;
48}
49
48ed9c23 50/* Test of EVP_PKEY_METHOD ordering */
31a80694 51static int test_pkey_meths(void)
48ed9c23
DSH
52{
53 size_t i;
54 int prev = -1;
55 int good = 1;
56 int pkey_id;
57 const EVP_PKEY_METHOD *pmeth;
58
59 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
60 pmeth = EVP_PKEY_meth_get0(i);
61 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
62 if (pkey_id < prev)
63 good = 0;
64 prev = pkey_id;
65
66 }
67 if (!good) {
68 TEST_error("EVP_PKEY_METHOD table out of order");
69 for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
70 pmeth = EVP_PKEY_meth_get0(i);
71 EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
72 TEST_note("%d : %s", pkey_id, OBJ_nid2ln(pkey_id));
73 }
74 }
75 return good;
76}
77
3cb7c5cf 78int setup_tests(void)
52fe14e6
DSH
79{
80 ADD_TEST(test_asn1_meths);
48ed9c23 81 ADD_TEST(test_pkey_meths);
ad887416 82 return 1;
52fe14e6 83}