Move OPENSSL_add_builtin back into provider.c

An earlier stage of the refactor in the last few commits moved this
function out of provider.c because it needed access to the provider
structure internals. The final version however no longer needs this so
it is moved back again.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15854)
This commit is contained in:
Matt Caswell 2021-06-22 12:07:48 +01:00
parent 29d46e09ce
commit d382c46525
2 changed files with 25 additions and 23 deletions

View File

@ -7,11 +7,13 @@
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include <openssl/err.h>
#include <openssl/cryptoerr.h>
#include <openssl/provider.h>
#include <openssl/core_names.h>
#include "internal/provider.h"
#include "provider_local.h"
OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name,
int retain_fallbacks)
@ -103,6 +105,29 @@ int OSSL_PROVIDER_get_capabilities(const OSSL_PROVIDER *prov,
return ossl_provider_get_capabilities(prov, capability, cb, arg);
}
int OSSL_PROVIDER_add_builtin(OSSL_LIB_CTX *libctx, const char *name,
OSSL_provider_init_fn *init_fn)
{
OSSL_PROVIDER_INFO entry;
if (name == NULL || init_fn == NULL) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
memset(&entry, 0, sizeof(entry));
entry.name = OPENSSL_strdup(name);
if (entry.name == NULL) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
return 0;
}
entry.init = init_fn;
if (!ossl_provider_info_add_to_store(libctx, &entry)) {
ossl_provider_info_clear(&entry);
return 0;
}
return 1;
}
const char *OSSL_PROVIDER_get0_name(const OSSL_PROVIDER *prov)
{
return ossl_provider_name(prov);

View File

@ -319,29 +319,6 @@ int ossl_provider_info_add_to_store(OSSL_LIB_CTX *libctx,
return ret;
}
int OSSL_PROVIDER_add_builtin(OSSL_LIB_CTX *libctx, const char *name,
OSSL_provider_init_fn *init_fn)
{
OSSL_PROVIDER_INFO entry;
if (name == NULL || init_fn == NULL) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
memset(&entry, 0, sizeof(entry));
entry.name = OPENSSL_strdup(name);
if (entry.name == NULL) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
return 0;
}
entry.init = init_fn;
if (!ossl_provider_info_add_to_store(libctx, &entry)) {
ossl_provider_info_clear(&entry);
return 0;
}
return 1;
}
OSSL_PROVIDER *ossl_provider_find(OSSL_LIB_CTX *libctx, const char *name,
int noconfig)
{