]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/testutil/provider.c
Rename OPENSSL_CTX prefix to OSSL_LIB_CTX
[thirdparty/openssl.git] / test / testutil / provider.c
CommitLineData
1bb6f70d
DDO
1/*
2 * Copyright 2018-2020 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 "../testutil.h"
11#include <openssl/provider.h>
12#include <string.h>
13
b4250010 14int test_get_libctx(OSSL_LIB_CTX **libctx,
1bb6f70d
DDO
15 OSSL_PROVIDER **default_null_provider,
16 OSSL_PROVIDER **provider, int argn, const char *usage)
17{
18 const char *module_name;
19
20 if (!TEST_ptr(module_name = test_get_argument(argn))) {
21 TEST_error("usage: <prog> %s", usage);
22 return 0;
23 }
24 if (strcmp(module_name, "none") != 0) {
25 const char *config_fname = test_get_argument(argn + 1);
26
27 *default_null_provider = OSSL_PROVIDER_load(NULL, "null");
b4250010 28 *libctx = OSSL_LIB_CTX_new();
1bb6f70d
DDO
29 if (!TEST_ptr(*libctx)) {
30 TEST_error("Failed to create libctx\n");
31 goto err;
32 }
33
34 if (config_fname != NULL
b4250010 35 && !TEST_true(OSSL_LIB_CTX_load_config(*libctx, config_fname))) {
1bb6f70d
DDO
36 TEST_error("Error loading config file %s\n", config_fname);
37 goto err;
38 }
39
40 *provider = OSSL_PROVIDER_load(*libctx, module_name);
41 if (!TEST_ptr(*provider)) {
42 TEST_error("Failed to load provider %s\n", module_name);
43 goto err;
44 }
45 }
46 return 1;
47
48 err:
49 ERR_print_errors_fp(stderr);
50 return 0;
51}