1/*
2 * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#include <openssl/evp.h>
11#include "testutil.h"
12
13static char *config_file = NULL;
14
15typedef enum OPTION_choice {
16    OPT_ERR = -1,
17    OPT_EOF = 0,
18    OPT_CONFIG_FILE,
19    OPT_TEST_ENUM
20} OPTION_CHOICE;
21
22const OPTIONS *test_get_options(void)
23{
24    static const OPTIONS options[] = {
25        OPT_TEST_OPTIONS_DEFAULT_USAGE,
26        { "config", OPT_CONFIG_FILE, '<',
27          "The configuration file to use for the libctx" },
28        { NULL }
29    };
30    return options;
31}
32
33
34/*
35 * Test that parsing a config file with incorrect stable settings aren't parsed
36 * and appropriate errors are raised
37 */
38static int test_asn1_stable_parse(void)
39{
40    int testret = 0;
41    unsigned long errcode;
42    OSSL_LIB_CTX *newctx = OSSL_LIB_CTX_new();
43
44    if (!TEST_ptr(newctx))
45        goto out;
46
47    if (!TEST_int_eq(OSSL_LIB_CTX_load_config(newctx, config_file), 0))
48        goto err;
49
50    errcode = ERR_peek_error();
51    if (ERR_GET_LIB(errcode) != ERR_LIB_ASN1)
52        goto err;
53    if (ERR_GET_REASON(errcode) != ASN1_R_INVALID_STRING_TABLE_VALUE)
54        goto err;
55
56    ERR_clear_error();
57
58    testret = 1;
59err:
60    OSSL_LIB_CTX_free(newctx);
61out:
62    return testret;
63}
64
65int setup_tests(void)
66{
67    OPTION_CHOICE o;
68
69    while ((o = opt_next()) != OPT_EOF) {
70        switch (o) {
71        case OPT_CONFIG_FILE:
72            config_file = opt_arg();
73            break;
74        default:
75            return 0;
76        }
77    }
78
79    ADD_TEST(test_asn1_stable_parse);
80    return 1;
81}
82