Ignore dups in X509_STORE_add_*
[openssl.git] / test / pbelutest.c
1 /*
2  * Copyright 2015-2016 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 #include <openssl/evp.h>
11 #include "testutil.h"
12 #include "test_main.h"
13
14 /*
15  * Password based encryption (PBE) table ordering test.
16  * Attempt to look up all supported algorithms.
17  */
18
19 static int test_pbelu(void)
20 {
21     int i, failed = 0, ok;
22     int pbe_type, pbe_nid, last_type = -1, last_nid = -1;
23
24     for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
25         if (!TEST_true(EVP_PBE_find(pbe_type, pbe_nid, NULL, NULL, 0))) {
26             TEST_info("i=%d, pbe_type=%d, pbe_nid=%d", i, pbe_type, pbe_nid);
27             failed = 1;
28             break;
29         }
30     }
31
32     if (!failed)
33         return 1;
34
35     /* Error: print out whole table */
36     for (i = 0; EVP_PBE_get(&pbe_type, &pbe_nid, i) != 0; i++) {
37         if (pbe_type > last_type)
38             ok = 0;
39         else if (pbe_type < last_type || pbe_nid < last_nid)
40             ok = 1;
41         else
42             ok = 0;
43         if (!ok)
44             failed = 1;
45         TEST_info("PBE type=%d %d (%s): %s\n", pbe_type, pbe_nid,
46                 OBJ_nid2sn(pbe_nid), ok ? "ERROR" : "OK");
47         last_type = pbe_type;
48         last_nid = pbe_nid;
49     }
50     return failed ? 0 : 1;
51 }
52
53 void register_tests(void)
54 {
55     ADD_TEST(test_pbelu);
56 }