indicator_core.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2024 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/indicator.h>
  10. #include <openssl/core_names.h>
  11. #include <openssl/params.h>
  12. #include "internal/cryptlib.h"
  13. #include "crypto/context.h"
  14. typedef struct indicator_cb_st
  15. {
  16. OSSL_INDICATOR_CALLBACK *cb;
  17. } INDICATOR_CB;
  18. void *ossl_indicator_set_callback_new(OSSL_LIB_CTX *ctx)
  19. {
  20. INDICATOR_CB *cb;
  21. cb = OPENSSL_zalloc(sizeof(*cb));
  22. return cb;
  23. }
  24. void ossl_indicator_set_callback_free(void *cb)
  25. {
  26. OPENSSL_free(cb);
  27. }
  28. static INDICATOR_CB *get_indicator_callback(OSSL_LIB_CTX *libctx)
  29. {
  30. return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_INDICATOR_CB_INDEX);
  31. }
  32. void OSSL_INDICATOR_set_callback(OSSL_LIB_CTX *libctx,
  33. OSSL_INDICATOR_CALLBACK *cb)
  34. {
  35. INDICATOR_CB *icb = get_indicator_callback(libctx);
  36. if (icb != NULL)
  37. icb->cb = cb;
  38. }
  39. void OSSL_INDICATOR_get_callback(OSSL_LIB_CTX *libctx,
  40. OSSL_INDICATOR_CALLBACK **cb)
  41. {
  42. INDICATOR_CB *icb = get_indicator_callback(libctx);
  43. if (cb != NULL)
  44. *cb = (icb != NULL ? icb->cb : NULL);
  45. }