diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-09-26 15:21:48 +0200 |
---|---|---|
committer | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-12-10 11:01:26 +0100 |
commit | bca7ad6efd0e1e828033cae2440d83322bf3dc01 (patch) | |
tree | 57d6dc04ab9481e63ca61e2b5174ce1cc641018f /test/testutil | |
parent | 5ea64b456b1a27ae046f23d632a968a7583bb9eb (diff) | |
download | openssl-bca7ad6efd0e1e828033cae2440d83322bf3dc01.zip openssl-bca7ad6efd0e1e828033cae2440d83322bf3dc01.tar.gz openssl-bca7ad6efd0e1e828033cae2440d83322bf3dc01.tar.bz2 |
Use adapted test_get_libctx() for simpler test setup and better error reporting
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13001)
Diffstat (limited to 'test/testutil')
-rw-r--r-- | test/testutil/provider.c | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/test/testutil/provider.c b/test/testutil/provider.c index c7ff44c..c50ef03 100644 --- a/test/testutil/provider.c +++ b/test/testutil/provider.c @@ -11,37 +11,31 @@ #include <openssl/provider.h> #include <string.h> -int test_get_libctx(OSSL_LIB_CTX **libctx, - OSSL_PROVIDER **default_null_provider, - OSSL_PROVIDER **provider, int argn, const char *usage) +int test_get_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov, + const char *config_file, + OSSL_PROVIDER **provider, const char *module_name) { - const char *module_name; + if ((*libctx = OSSL_LIB_CTX_new()) == NULL) { + opt_printf_stderr("Failed to create libctx\n"); + goto err; + } - if (!TEST_ptr(module_name = test_get_argument(argn))) { - TEST_error("usage: <prog> %s", usage); - return 0; + if (default_null_prov != NULL + && (*default_null_prov = OSSL_PROVIDER_load(NULL, "null")) == NULL) { + opt_printf_stderr("Failed to load null provider into default libctx\n"); + goto err; } - if (strcmp(module_name, "none") != 0) { - const char *config_fname = test_get_argument(argn + 1); - - *default_null_provider = OSSL_PROVIDER_load(NULL, "null"); - *libctx = OSSL_LIB_CTX_new(); - if (!TEST_ptr(*libctx)) { - TEST_error("Failed to create libctx\n"); - goto err; - } - - if (config_fname != NULL - && !TEST_true(OSSL_LIB_CTX_load_config(*libctx, config_fname))) { - TEST_error("Error loading config file %s\n", config_fname); - goto err; - } - - *provider = OSSL_PROVIDER_load(*libctx, module_name); - if (!TEST_ptr(*provider)) { - TEST_error("Failed to load provider %s\n", module_name); - goto err; - } + + if (config_file != NULL + && !OSSL_LIB_CTX_load_config(*libctx, config_file)) { + opt_printf_stderr("Error loading config from file %s\n", config_file); + goto err; + } + + if (module_name != NULL + && (*provider = OSSL_PROVIDER_load(*libctx, module_name)) == NULL) { + opt_printf_stderr("Failed to load provider %s\n", module_name); + goto err; } return 1; @@ -49,3 +43,18 @@ int test_get_libctx(OSSL_LIB_CTX **libctx, ERR_print_errors_fp(stderr); return 0; } + +int test_arg_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov, + OSSL_PROVIDER **provider, int argn, const char *usage) +{ + const char *module_name; + + if (!TEST_ptr(module_name = test_get_argument(argn))) { + TEST_error("usage: <prog> %s", usage); + return 0; + } + if (strcmp(module_name, "none") == 0) + return 1; + return test_get_libctx(libctx, default_null_prov, + test_get_argument(argn + 1), provider, module_name); +} |