1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci#include "app_libctx.h"
10e1051a39Sopenharmony_ci#include "apps.h"
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_cistatic OSSL_LIB_CTX *app_libctx = NULL;
13e1051a39Sopenharmony_cistatic const char *app_propq = NULL;
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_ciint app_set_propq(const char *arg)
16e1051a39Sopenharmony_ci{
17e1051a39Sopenharmony_ci    app_propq = arg;
18e1051a39Sopenharmony_ci    return 1;
19e1051a39Sopenharmony_ci}
20e1051a39Sopenharmony_ci
21e1051a39Sopenharmony_ciconst char *app_get0_propq(void)
22e1051a39Sopenharmony_ci{
23e1051a39Sopenharmony_ci    return app_propq;
24e1051a39Sopenharmony_ci}
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ciOSSL_LIB_CTX *app_get0_libctx(void)
27e1051a39Sopenharmony_ci{
28e1051a39Sopenharmony_ci    return app_libctx;
29e1051a39Sopenharmony_ci}
30e1051a39Sopenharmony_ci
31e1051a39Sopenharmony_ciOSSL_LIB_CTX *app_create_libctx(void)
32e1051a39Sopenharmony_ci{
33e1051a39Sopenharmony_ci    /*
34e1051a39Sopenharmony_ci     * Load the NULL provider into the default library context and create a
35e1051a39Sopenharmony_ci     * library context which will then be used for any OPT_PROV options.
36e1051a39Sopenharmony_ci     */
37e1051a39Sopenharmony_ci    if (app_libctx == NULL) {
38e1051a39Sopenharmony_ci        if (!app_provider_load(NULL, "null")) {
39e1051a39Sopenharmony_ci            opt_printf_stderr( "Failed to create null provider\n");
40e1051a39Sopenharmony_ci            return NULL;
41e1051a39Sopenharmony_ci        }
42e1051a39Sopenharmony_ci        app_libctx = OSSL_LIB_CTX_new();
43e1051a39Sopenharmony_ci    }
44e1051a39Sopenharmony_ci    if (app_libctx == NULL)
45e1051a39Sopenharmony_ci        opt_printf_stderr("Failed to create library context\n");
46e1051a39Sopenharmony_ci    return app_libctx;
47e1051a39Sopenharmony_ci}
48e1051a39Sopenharmony_ci
49