From: Viktor Dukhovni Date: Fri, 24 Jan 2025 01:52:25 +0000 (+1100) Subject: Also expose an accessor for a single string provider config property X-Git-Tag: openssl-3.5.0-alpha1~684 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95a3662626602c7298170849819e02002b7add42;p=thirdparty%2Fopenssl.git Also expose an accessor for a single string provider config property Reviewed-by: Dmitry Belyavskiy Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/26550) --- diff --git a/providers/common/include/prov/provider_ctx.h b/providers/common/include/prov/provider_ctx.h index 069ec99a21c..faa17c0d314 100644 --- a/providers/common/include/prov/provider_ctx.h +++ b/providers/common/include/prov/provider_ctx.h @@ -42,6 +42,8 @@ OSSL_LIB_CTX *ossl_prov_ctx_get0_libctx(PROV_CTX *ctx); const OSSL_CORE_HANDLE *ossl_prov_ctx_get0_handle(PROV_CTX *ctx); BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(PROV_CTX *ctx); OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx); +const char * +ossl_prov_ctx_get_param(PROV_CTX *ctx, const char *name, const char *defval); int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval); #endif diff --git a/providers/common/provider_ctx.c b/providers/common/provider_ctx.c index 4a6cf621e27..8d4cd280f1b 100644 --- a/providers/common/provider_ctx.c +++ b/providers/common/provider_ctx.c @@ -76,7 +76,8 @@ OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx) return ctx->core_get_params; } -int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval) +const char * +ossl_prov_ctx_get_param(PROV_CTX *ctx, const char *name, const char *defval) { char *val = NULL; OSSL_PARAM param[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; @@ -86,7 +87,7 @@ int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval) || ctx->core_get_params == NULL) return defval; - param[0].key = (char *)name; + param[0].key = (char *) name; param[0].data_type = OSSL_PARAM_UTF8_PTR; param[0].data = (void *) &val; param[0].data_size = sizeof(val); @@ -95,7 +96,16 @@ int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval) /* Errors are ignored, returning the default value */ if (ctx->core_get_params(ctx->handle, param) && OSSL_PARAM_modified(param) - && val != NULL) { + && val != NULL) + return val; + return defval; +} + +int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval) +{ + const char *val = ossl_prov_ctx_get_param(ctx, name, NULL); + + if (val != NULL) { if ((strcmp(val, "1") == 0) || (OPENSSL_strcasecmp(val, "yes") == 0) || (OPENSSL_strcasecmp(val, "true") == 0)