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