provider.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, OSSL_PROVIDER **default_null_prov,
  13. const char *config_file,
  14. OSSL_PROVIDER **provider, const char *module_name)
  15. {
  16. OSSL_LIB_CTX *new_libctx = NULL;
  17. if (libctx != NULL) {
  18. if ((new_libctx = *libctx = OSSL_LIB_CTX_new()) == NULL) {
  19. opt_printf_stderr("Failed to create libctx\n");
  20. goto err;
  21. }
  22. }
  23. if (default_null_prov != NULL
  24. && (*default_null_prov = OSSL_PROVIDER_load(NULL, "null")) == NULL) {
  25. opt_printf_stderr("Failed to load null provider into default libctx\n");
  26. goto err;
  27. }
  28. if (config_file != NULL
  29. && !OSSL_LIB_CTX_load_config(new_libctx, config_file)) {
  30. opt_printf_stderr("Error loading config from file %s\n", config_file);
  31. goto err;
  32. }
  33. if (module_name != NULL
  34. && (*provider = OSSL_PROVIDER_load(new_libctx, module_name)) == NULL) {
  35. opt_printf_stderr("Failed to load provider %s\n", module_name);
  36. goto err;
  37. }
  38. return 1;
  39. err:
  40. ERR_print_errors_fp(stderr);
  41. return 0;
  42. }
  43. int test_arg_libctx(OSSL_LIB_CTX **libctx, OSSL_PROVIDER **default_null_prov,
  44. OSSL_PROVIDER **provider, int argn, const char *usage)
  45. {
  46. const char *module_name;
  47. if (!TEST_ptr(module_name = test_get_argument(argn))) {
  48. TEST_error("usage: <prog> %s", usage);
  49. return 0;
  50. }
  51. if (strcmp(module_name, "none") == 0)
  52. return 1;
  53. return test_get_libctx(libctx, default_null_prov,
  54. test_get_argument(argn + 1), provider, module_name);
  55. }