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