xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/openssl-compat.h (revision f8cf1a9151c7af1cb0bd8b09c13c66bca599c027)
1 /*	$NetBSD: openssl-compat.h,v 1.2 2024/08/18 20:47:21 christos Exp $	*/
2 
3 #ifndef OPENSSL_COMPAT_H
4 #define OPENSSL_COMPAT_H
5 
6 #include <openssl/bio.h>
7 #include "util-internal.h"
8 
9 #if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
10 	(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
11 
12 static inline BIO_METHOD *BIO_meth_new(int type, const char *name)
13 {
14 	BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD));
15 
16 	if (biom != NULL) {
17 		biom->type = type;
18 		biom->name = name;
19 	}
20 	return biom;
21 }
22 
23 #define BIO_meth_set_write(b, f) (b)->bwrite = (f)
24 #define BIO_meth_set_read(b, f) (b)->bread = (f)
25 #define BIO_meth_set_puts(b, f) (b)->bputs = (f)
26 #define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f)
27 #define BIO_meth_set_create(b, f) (b)->create = (f)
28 #define BIO_meth_set_destroy(b, f) (b)->destroy = (f)
29 
30 #define BIO_set_init(b, val) (b)->init = (val)
31 #define BIO_set_data(b, val) (b)->ptr = (val)
32 #define BIO_set_shutdown(b, val) (b)->shutdown = (val)
33 #define BIO_get_init(b) (b)->init
34 #define BIO_get_data(b) (b)->ptr
35 #define BIO_get_shutdown(b) (b)->shutdown
36 
37 #define TLS_method SSLv23_method
38 
39 #define X509_getm_notBefore X509_get_notBefore
40 #define X509_getm_notAfter X509_get_notAfter
41 
42 #endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
43 	(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */
44 
45 #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L
46 #define BIO_get_init(b) (b)->init
47 #endif
48 
49 #endif /* OPENSSL_COMPAT_H */
50