xref: /freebsd/crypto/openssl/crypto/indicator_core.c (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
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     OSSL_INDICATOR_CALLBACK *cb;
18 } INDICATOR_CB;
19 
ossl_indicator_set_callback_new(OSSL_LIB_CTX * ctx)20 void *ossl_indicator_set_callback_new(OSSL_LIB_CTX *ctx)
21 {
22     INDICATOR_CB *cb;
23 
24     cb = OPENSSL_zalloc(sizeof(*cb));
25     return cb;
26 }
27 
ossl_indicator_set_callback_free(void * cb)28 void ossl_indicator_set_callback_free(void *cb)
29 {
30     OPENSSL_free(cb);
31 }
32 
get_indicator_callback(OSSL_LIB_CTX * libctx)33 static INDICATOR_CB *get_indicator_callback(OSSL_LIB_CTX *libctx)
34 {
35     return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_INDICATOR_CB_INDEX);
36 }
37 
OSSL_INDICATOR_set_callback(OSSL_LIB_CTX * libctx,OSSL_INDICATOR_CALLBACK * cb)38 void OSSL_INDICATOR_set_callback(OSSL_LIB_CTX *libctx,
39     OSSL_INDICATOR_CALLBACK *cb)
40 {
41     INDICATOR_CB *icb = get_indicator_callback(libctx);
42 
43     if (icb != NULL)
44         icb->cb = cb;
45 }
46 
OSSL_INDICATOR_get_callback(OSSL_LIB_CTX * libctx,OSSL_INDICATOR_CALLBACK ** cb)47 void OSSL_INDICATOR_get_callback(OSSL_LIB_CTX *libctx,
48     OSSL_INDICATOR_CALLBACK **cb)
49 {
50     INDICATOR_CB *icb = get_indicator_callback(libctx);
51 
52     if (cb != NULL)
53         *cb = (icb != NULL ? icb->cb : NULL);
54 }
55