Move SM2 algos to SM2 specific PKEY method
[openssl.git] / test / pkey_meth_test.c
1 /*
2  * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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
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"
17
18 /* Test of EVP_PKEY_ASN1_METHOD ordering */
19 static int test_asn1_meths(void)
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) {
36         TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
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>";
44             TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
45         }
46     }
47     return good;
48 }
49
50 /* Test of EVP_PKEY_METHOD ordering */
51 static int test_pkey_meths(void)
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
78 int setup_tests(void)
79 {
80     ADD_TEST(test_asn1_meths);
81     ADD_TEST(test_pkey_meths);
82     return 1;
83 }