provider_test.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2019 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 <stddef.h>
  10. #include <openssl/provider.h>
  11. #include "testutil.h"
  12. extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
  13. static char buf[256];
  14. static OSSL_PARAM greeting_request[] = {
  15. { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf) },
  16. { NULL, 0, NULL, 0, 0 }
  17. };
  18. static int test_provider(const char *name)
  19. {
  20. OSSL_PROVIDER *prov = NULL;
  21. const char *greeting = NULL;
  22. char expected_greeting[256];
  23. BIO_snprintf(expected_greeting, sizeof(expected_greeting),
  24. "Hello OpenSSL %.20s, greetings from %s!",
  25. OPENSSL_VERSION_STR, name);
  26. return
  27. TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name))
  28. && TEST_true(OSSL_PROVIDER_get_params(prov, greeting_request))
  29. && TEST_ptr(greeting = greeting_request[0].data)
  30. && TEST_size_t_gt(greeting_request[0].data_size, 0)
  31. && TEST_str_eq(greeting, expected_greeting)
  32. && TEST_true(OSSL_PROVIDER_unload(prov));
  33. }
  34. static int test_builtin_provider(void)
  35. {
  36. const char *name = "p_test_builtin";
  37. return
  38. TEST_true(OSSL_PROVIDER_add_builtin(NULL, name,
  39. PROVIDER_INIT_FUNCTION_NAME))
  40. && test_provider(name);
  41. }
  42. #ifndef NO_PROVIDER_MODULE
  43. static int test_loaded_provider(void)
  44. {
  45. const char *name = "p_test";
  46. return test_provider(name);
  47. }
  48. #endif
  49. int setup_tests(void)
  50. {
  51. ADD_TEST(test_builtin_provider);
  52. #ifndef NO_PROVIDER_MODULE
  53. ADD_TEST(test_loaded_provider);
  54. #endif
  55. return 1;
  56. }