2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <openssl/core_numbers.h>
13 static OSSL_BIO_new_file_fn *c_bio_new_file = NULL;
14 static OSSL_BIO_new_membuf_fn *c_bio_new_membuf = NULL;
15 static OSSL_BIO_read_ex_fn *c_bio_read_ex = NULL;
16 static OSSL_BIO_free_fn *c_bio_free = NULL;
17 static OSSL_BIO_vprintf_fn *c_bio_vprintf = NULL;
19 int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns)
21 for (; fns->function_id != 0; fns++) {
22 switch (fns->function_id) {
23 case OSSL_FUNC_BIO_NEW_FILE:
24 if (c_bio_new_file == NULL)
25 c_bio_new_file = OSSL_get_BIO_new_file(fns);
27 case OSSL_FUNC_BIO_NEW_MEMBUF:
28 if (c_bio_new_membuf == NULL)
29 c_bio_new_membuf = OSSL_get_BIO_new_membuf(fns);
31 case OSSL_FUNC_BIO_READ_EX:
32 if (c_bio_read_ex == NULL)
33 c_bio_read_ex = OSSL_get_BIO_read_ex(fns);
35 case OSSL_FUNC_BIO_FREE:
36 if (c_bio_free == NULL)
37 c_bio_free = OSSL_get_BIO_free(fns);
39 case OSSL_FUNC_BIO_VPRINTF:
40 if (c_bio_vprintf == NULL)
41 c_bio_vprintf = OSSL_get_BIO_vprintf(fns);
49 BIO *ossl_prov_bio_new_file(const char *filename, const char *mode)
51 if (c_bio_new_file == NULL)
53 return c_bio_new_file(filename, mode);
56 BIO *ossl_prov_bio_new_membuf(const char *filename, int len)
58 if (c_bio_new_membuf == NULL)
60 return c_bio_new_membuf(filename, len);
63 int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len,
66 if (c_bio_read_ex == NULL)
68 return c_bio_read_ex(bio, data, data_len, bytes_read);
71 int ossl_prov_bio_free(BIO *bio)
73 if (c_bio_free == NULL)
75 return c_bio_free(bio);
78 int ossl_prov_bio_vprintf(BIO *bio, const char *format, va_list ap)
80 if (c_bio_vprintf == NULL)
82 return c_bio_vprintf(bio, format, ap);
85 int ossl_prov_bio_printf(BIO *bio, const char *format, ...)
91 ret = ossl_prov_bio_vprintf(bio, format, ap);