xref: /openbsd-src/lib/libcrypto/bio/bio_meth.c (revision acf644016ec1190723fc541ba590471e90a9ef53)
1*acf64401Sbeck /*	$OpenBSD: bio_meth.c,v 1.9 2023/07/05 21:23:37 beck Exp $	*/
297c7ad8eStb /*
397c7ad8eStb  * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
497c7ad8eStb  *
597c7ad8eStb  * Permission to use, copy, modify, and distribute this software for any
697c7ad8eStb  * purpose with or without fee is hereby granted, provided that the above
797c7ad8eStb  * copyright notice and this permission notice appear in all copies.
897c7ad8eStb  *
997c7ad8eStb  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1097c7ad8eStb  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1197c7ad8eStb  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1297c7ad8eStb  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1397c7ad8eStb  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1497c7ad8eStb  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1597c7ad8eStb  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1697c7ad8eStb  */
1797c7ad8eStb 
1897c7ad8eStb #include <stdlib.h>
1997c7ad8eStb 
2097c7ad8eStb #include <openssl/bio.h>
2197c7ad8eStb 
2294b1984eStb #include "bio_local.h"
2394b1984eStb 
2497c7ad8eStb BIO_METHOD *
BIO_meth_new(int type,const char * name)2597c7ad8eStb BIO_meth_new(int type, const char *name)
2697c7ad8eStb {
2797c7ad8eStb 	BIO_METHOD *biom;
2897c7ad8eStb 
2997c7ad8eStb 	if ((biom = calloc(1, sizeof(*biom))) == NULL)
3097c7ad8eStb 		return NULL;
3197c7ad8eStb 
3297c7ad8eStb 	biom->type = type;
3397c7ad8eStb 	biom->name = name;
3497c7ad8eStb 
3597c7ad8eStb 	return biom;
3697c7ad8eStb }
37*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_new);
3897c7ad8eStb 
3997c7ad8eStb void
BIO_meth_free(BIO_METHOD * biom)4097c7ad8eStb BIO_meth_free(BIO_METHOD *biom)
4197c7ad8eStb {
4297c7ad8eStb 	free(biom);
4397c7ad8eStb }
44*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_free);
4597c7ad8eStb 
4697c7ad8eStb int
BIO_meth_get_write(const BIO_METHOD * biom)478625b501Stb (*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int)
4857f42a4cStb {
4957f42a4cStb 	return biom->bwrite;
5057f42a4cStb }
51*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_write);
5257f42a4cStb 
5357f42a4cStb int
BIO_meth_set_write(BIO_METHOD * biom,int (* write)(BIO *,const char *,int))5497c7ad8eStb BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
5597c7ad8eStb {
5697c7ad8eStb 	biom->bwrite = write;
5797c7ad8eStb 	return 1;
5897c7ad8eStb }
59*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_write);
6097c7ad8eStb 
6197c7ad8eStb int
BIO_meth_get_read(const BIO_METHOD * biom)628625b501Stb (*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int)
6357f42a4cStb {
6457f42a4cStb 	return biom->bread;
6557f42a4cStb }
66*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_read);
6757f42a4cStb 
6857f42a4cStb int
BIO_meth_set_read(BIO_METHOD * biom,int (* read)(BIO *,char *,int))6997c7ad8eStb BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
7097c7ad8eStb {
7197c7ad8eStb 	biom->bread = read;
7297c7ad8eStb 	return 1;
7397c7ad8eStb }
74*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_read);
7597c7ad8eStb 
7697c7ad8eStb int
BIO_meth_get_puts(const BIO_METHOD * biom)778625b501Stb (*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *)
7857f42a4cStb {
7957f42a4cStb 	return biom->bputs;
8057f42a4cStb }
81*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_puts);
8257f42a4cStb 
8357f42a4cStb int
BIO_meth_set_puts(BIO_METHOD * biom,int (* puts)(BIO *,const char *))8497c7ad8eStb BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
8597c7ad8eStb {
8697c7ad8eStb 	biom->bputs = puts;
8797c7ad8eStb 	return 1;
8897c7ad8eStb }
89*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_puts);
9097c7ad8eStb 
9197c7ad8eStb int
BIO_meth_get_gets(const BIO_METHOD * biom)928625b501Stb (*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int)
9357f42a4cStb {
9457f42a4cStb 	return biom->bgets;
9557f42a4cStb }
96*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_gets);
9757f42a4cStb 
9857f42a4cStb int
BIO_meth_set_gets(BIO_METHOD * biom,int (* gets)(BIO *,char *,int))99f02021ddStb BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int))
100f02021ddStb {
101f02021ddStb 	biom->bgets = gets;
102f02021ddStb 	return 1;
103f02021ddStb }
104*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_gets);
105f02021ddStb 
10657f42a4cStb long
BIO_meth_get_ctrl(const BIO_METHOD * biom)1078625b501Stb (*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *)
10857f42a4cStb {
10957f42a4cStb 	return biom->ctrl;
11057f42a4cStb }
111*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_ctrl);
11257f42a4cStb 
113f02021ddStb int
BIO_meth_set_ctrl(BIO_METHOD * biom,long (* ctrl)(BIO *,int,long,void *))11497c7ad8eStb BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
11597c7ad8eStb {
11697c7ad8eStb 	biom->ctrl = ctrl;
11797c7ad8eStb 	return 1;
11897c7ad8eStb }
119*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_ctrl);
12097c7ad8eStb 
12197c7ad8eStb int
BIO_meth_get_create(const BIO_METHOD * biom)1228625b501Stb (*BIO_meth_get_create(const BIO_METHOD *biom))(BIO *)
12357f42a4cStb {
12457f42a4cStb 	return biom->create;
12557f42a4cStb }
126*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_create);
12757f42a4cStb 
12857f42a4cStb int
BIO_meth_set_create(BIO_METHOD * biom,int (* create)(BIO *))12997c7ad8eStb BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
13097c7ad8eStb {
13197c7ad8eStb 	biom->create = create;
13297c7ad8eStb 	return 1;
13397c7ad8eStb }
134*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_create);
13597c7ad8eStb 
13697c7ad8eStb int
BIO_meth_get_destroy(const BIO_METHOD * biom)1378625b501Stb (*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *)
13857f42a4cStb {
13957f42a4cStb 	return biom->destroy;
14057f42a4cStb }
141*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_destroy);
14257f42a4cStb 
14357f42a4cStb int
BIO_meth_set_destroy(BIO_METHOD * biom,int (* destroy)(BIO *))14497c7ad8eStb BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
14597c7ad8eStb {
14697c7ad8eStb 	biom->destroy = destroy;
14797c7ad8eStb 	return 1;
14897c7ad8eStb }
149*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_destroy);
1505fd87cb9Stb 
1515fd87cb9Stb long
BIO_meth_get_callback_ctrl(const BIO_METHOD * biom)1528625b501Stb (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
1535fd87cb9Stb {
154818427c5Stb 	return biom->callback_ctrl;
1555fd87cb9Stb }
156*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_get_callback_ctrl);
1575fd87cb9Stb 
1585fd87cb9Stb int
BIO_meth_set_callback_ctrl(BIO_METHOD * biom,long (* callback_ctrl)(BIO *,int,BIO_info_cb *))1595fd87cb9Stb BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
1605fd87cb9Stb     long (*callback_ctrl)(BIO *, int, BIO_info_cb *))
1615fd87cb9Stb {
162818427c5Stb 	biom->callback_ctrl = callback_ctrl;
1635fd87cb9Stb 	return 1;
1645fd87cb9Stb }
165*acf64401Sbeck LCRYPTO_ALIAS(BIO_meth_set_callback_ctrl);
166