xref: /openbsd/lib/libcrypto/bio/bio_meth.c (revision acf64401)
1 /*	$OpenBSD: bio_meth.c,v 1.9 2023/07/05 21:23:37 beck Exp $	*/
2 /*
3  * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <stdlib.h>
19 
20 #include <openssl/bio.h>
21 
22 #include "bio_local.h"
23 
24 BIO_METHOD *
BIO_meth_new(int type,const char * name)25 BIO_meth_new(int type, const char *name)
26 {
27 	BIO_METHOD *biom;
28 
29 	if ((biom = calloc(1, sizeof(*biom))) == NULL)
30 		return NULL;
31 
32 	biom->type = type;
33 	biom->name = name;
34 
35 	return biom;
36 }
37 LCRYPTO_ALIAS(BIO_meth_new);
38 
39 void
BIO_meth_free(BIO_METHOD * biom)40 BIO_meth_free(BIO_METHOD *biom)
41 {
42 	free(biom);
43 }
44 LCRYPTO_ALIAS(BIO_meth_free);
45 
46 int
BIO_meth_get_write(const BIO_METHOD * biom)47 (*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int)
48 {
49 	return biom->bwrite;
50 }
51 LCRYPTO_ALIAS(BIO_meth_get_write);
52 
53 int
BIO_meth_set_write(BIO_METHOD * biom,int (* write)(BIO *,const char *,int))54 BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
55 {
56 	biom->bwrite = write;
57 	return 1;
58 }
59 LCRYPTO_ALIAS(BIO_meth_set_write);
60 
61 int
BIO_meth_get_read(const BIO_METHOD * biom)62 (*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int)
63 {
64 	return biom->bread;
65 }
66 LCRYPTO_ALIAS(BIO_meth_get_read);
67 
68 int
BIO_meth_set_read(BIO_METHOD * biom,int (* read)(BIO *,char *,int))69 BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
70 {
71 	biom->bread = read;
72 	return 1;
73 }
74 LCRYPTO_ALIAS(BIO_meth_set_read);
75 
76 int
BIO_meth_get_puts(const BIO_METHOD * biom)77 (*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *)
78 {
79 	return biom->bputs;
80 }
81 LCRYPTO_ALIAS(BIO_meth_get_puts);
82 
83 int
BIO_meth_set_puts(BIO_METHOD * biom,int (* puts)(BIO *,const char *))84 BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
85 {
86 	biom->bputs = puts;
87 	return 1;
88 }
89 LCRYPTO_ALIAS(BIO_meth_set_puts);
90 
91 int
BIO_meth_get_gets(const BIO_METHOD * biom)92 (*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int)
93 {
94 	return biom->bgets;
95 }
96 LCRYPTO_ALIAS(BIO_meth_get_gets);
97 
98 int
BIO_meth_set_gets(BIO_METHOD * biom,int (* gets)(BIO *,char *,int))99 BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int))
100 {
101 	biom->bgets = gets;
102 	return 1;
103 }
104 LCRYPTO_ALIAS(BIO_meth_set_gets);
105 
106 long
BIO_meth_get_ctrl(const BIO_METHOD * biom)107 (*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *)
108 {
109 	return biom->ctrl;
110 }
111 LCRYPTO_ALIAS(BIO_meth_get_ctrl);
112 
113 int
BIO_meth_set_ctrl(BIO_METHOD * biom,long (* ctrl)(BIO *,int,long,void *))114 BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
115 {
116 	biom->ctrl = ctrl;
117 	return 1;
118 }
119 LCRYPTO_ALIAS(BIO_meth_set_ctrl);
120 
121 int
BIO_meth_get_create(const BIO_METHOD * biom)122 (*BIO_meth_get_create(const BIO_METHOD *biom))(BIO *)
123 {
124 	return biom->create;
125 }
126 LCRYPTO_ALIAS(BIO_meth_get_create);
127 
128 int
BIO_meth_set_create(BIO_METHOD * biom,int (* create)(BIO *))129 BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
130 {
131 	biom->create = create;
132 	return 1;
133 }
134 LCRYPTO_ALIAS(BIO_meth_set_create);
135 
136 int
BIO_meth_get_destroy(const BIO_METHOD * biom)137 (*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *)
138 {
139 	return biom->destroy;
140 }
141 LCRYPTO_ALIAS(BIO_meth_get_destroy);
142 
143 int
BIO_meth_set_destroy(BIO_METHOD * biom,int (* destroy)(BIO *))144 BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
145 {
146 	biom->destroy = destroy;
147 	return 1;
148 }
149 LCRYPTO_ALIAS(BIO_meth_set_destroy);
150 
151 long
BIO_meth_get_callback_ctrl(const BIO_METHOD * biom)152 (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
153 {
154 	return biom->callback_ctrl;
155 }
156 LCRYPTO_ALIAS(BIO_meth_get_callback_ctrl);
157 
158 int
BIO_meth_set_callback_ctrl(BIO_METHOD * biom,long (* callback_ctrl)(BIO *,int,BIO_info_cb *))159 BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
160     long (*callback_ctrl)(BIO *, int, BIO_info_cb *))
161 {
162 	biom->callback_ctrl = callback_ctrl;
163 	return 1;
164 }
165 LCRYPTO_ALIAS(BIO_meth_set_callback_ctrl);
166