provider.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "../testutil.h"
  10. #include <openssl/provider.h>
  11. #include <string.h>
  12. int test_get_libctx(OSSL_LIB_CTX **libctx,
  13. OSSL_PROVIDER **default_null_provider,
  14. OSSL_PROVIDER **provider, int argn, const char *usage)
  15. {
  16. const char *module_name;
  17. if (!TEST_ptr(module_name = test_get_argument(argn))) {
  18. TEST_error("usage: <prog> %s", usage);
  19. return 0;
  20. }
  21. if (strcmp(module_name, "none") != 0) {
  22. const char *config_fname = test_get_argument(argn + 1);
  23. *default_null_provider = OSSL_PROVIDER_load(NULL, "null");
  24. *libctx = OSSL_LIB_CTX_new();
  25. if (!TEST_ptr(*libctx)) {
  26. TEST_error("Failed to create libctx\n");
  27. goto err;
  28. }
  29. if (config_fname != NULL
  30. && !TEST_true(OSSL_LIB_CTX_load_config(*libctx, config_fname))) {
  31. TEST_error("Error loading config file %s\n", config_fname);
  32. goto err;
  33. }
  34. *provider = OSSL_PROVIDER_load(*libctx, module_name);
  35. if (!TEST_ptr(*provider)) {
  36. TEST_error("Failed to load provider %s\n", module_name);
  37. goto err;
  38. }
  39. }
  40. return 1;
  41. err:
  42. ERR_print_errors_fp(stderr);
  43. return 0;
  44. }