self_test_core.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <openssl/self_test.h>
  10. #include "internal/cryptlib.h"
  11. typedef struct self_test_cb_st
  12. {
  13. OSSL_CALLBACK *cb;
  14. void *cbarg;
  15. } SELF_TEST_CB;
  16. static void *self_test_set_callback_new(OPENSSL_CTX *ctx)
  17. {
  18. SELF_TEST_CB *stcb;
  19. stcb = OPENSSL_zalloc(sizeof(*stcb));
  20. return stcb;
  21. }
  22. static void self_test_set_callback_free(void *stcb)
  23. {
  24. OPENSSL_free(stcb);
  25. }
  26. static const OPENSSL_CTX_METHOD self_test_set_callback_method = {
  27. self_test_set_callback_new,
  28. self_test_set_callback_free,
  29. };
  30. static SELF_TEST_CB *get_self_test_callback(OPENSSL_CTX *libctx)
  31. {
  32. return openssl_ctx_get_data(libctx, OPENSSL_CTX_SELF_TEST_CB_INDEX,
  33. &self_test_set_callback_method);
  34. }
  35. void OSSL_SELF_TEST_set_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK *cb,
  36. void *cbarg)
  37. {
  38. SELF_TEST_CB *stcb = get_self_test_callback(libctx);
  39. if (stcb != NULL) {
  40. stcb->cb = cb;
  41. stcb->cbarg = cbarg;
  42. }
  43. }
  44. void OSSL_SELF_TEST_get_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK **cb,
  45. void **cbarg)
  46. {
  47. SELF_TEST_CB *stcb = get_self_test_callback(libctx);
  48. if (cb != NULL)
  49. *cb = (stcb != NULL ? stcb->cb : NULL);
  50. if (cbarg != NULL)
  51. *cbarg = (stcb != NULL ? stcb->cbarg : NULL);
  52. }