summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bio
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-02-17 13:57:15 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-02-17 13:57:15 +0000
commitf32acaad2272ac813ca700332ebf93990460b847 (patch)
tree3d825925f046ddc6793b53ae1627515a4f2e7c3e /lib/libcrypto/bio
parentc41474f135888179156e8edf1ee0dc486a6cf7c0 (diff)
Provide BIO_meth_{free,new}() and BIO_meth_set_{create,crtl,destroy}()
and BIO_meth_set_{puts,read,write}(). ok jsing
Diffstat (limited to 'lib/libcrypto/bio')
-rw-r--r--lib/libcrypto/bio/bio.h13
-rw-r--r--lib/libcrypto/bio/bio_meth.c82
2 files changed, 94 insertions, 1 deletions
diff --git a/lib/libcrypto/bio/bio.h b/lib/libcrypto/bio/bio.h
index faca1255442..3a1577ab37c 100644
--- a/lib/libcrypto/bio/bio.h
+++ b/lib/libcrypto/bio/bio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bio.h,v 1.30 2017/04/06 18:25:38 deraadt Exp $ */
+/* $OpenBSD: bio.h,v 1.31 2018/02/17 13:57:14 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -327,6 +327,17 @@ typedef struct bio_f_buffer_ctx_struct {
/* Prefix and suffix callback in ASN1 BIO */
typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg);
+/* BIO_METHOD accessors */
+BIO_METHOD *BIO_meth_new(int type, const char *name);
+void BIO_meth_free(BIO_METHOD *biom);
+int BIO_meth_set_write(BIO_METHOD *biom,
+ int (*write)(BIO *, const char *, int));
+int BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int));
+int BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *));
+int BIO_meth_set_ctrl(BIO_METHOD *biom,
+ int long (*ctrl)(BIO *, int, long, void *));
+int BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *));
+int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *));
/* connect BIO stuff */
#define BIO_CONN_S_BEFORE 1
diff --git a/lib/libcrypto/bio/bio_meth.c b/lib/libcrypto/bio/bio_meth.c
new file mode 100644
index 00000000000..83e5254304b
--- /dev/null
+++ b/lib/libcrypto/bio/bio_meth.c
@@ -0,0 +1,82 @@
+/* $OpenBSD: bio_meth.c,v 1.1 2018/02/17 13:57:14 tb Exp $ */
+/*
+ * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+
+#include <openssl/bio.h>
+
+BIO_METHOD *
+BIO_meth_new(int type, const char *name)
+{
+ BIO_METHOD *biom;
+
+ if ((biom = calloc(1, sizeof(*biom))) == NULL)
+ return NULL;
+
+ biom->type = type;
+ biom->name = name;
+
+ return biom;
+}
+
+void
+BIO_meth_free(BIO_METHOD *biom)
+{
+ free(biom);
+}
+
+int
+BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
+{
+ biom->bwrite = write;
+ return 1;
+}
+
+int
+BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
+{
+ biom->bread = read;
+ return 1;
+}
+
+int
+BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
+{
+ biom->bputs = puts;
+ return 1;
+}
+
+int
+BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
+{
+ biom->ctrl = ctrl;
+ return 1;
+}
+
+int
+BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
+{
+ biom->create = create;
+ return 1;
+}
+
+int
+BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
+{
+ biom->destroy = destroy;
+ return 1;
+}