1*acf64401Sbeck /* $OpenBSD: bss_null.c,v 1.13 2023/07/05 21:23:37 beck Exp $ */
25b37fcf3Sryker /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
35b37fcf3Sryker * All rights reserved.
45b37fcf3Sryker *
55b37fcf3Sryker * This package is an SSL implementation written
65b37fcf3Sryker * by Eric Young (eay@cryptsoft.com).
75b37fcf3Sryker * The implementation was written so as to conform with Netscapes SSL.
85b37fcf3Sryker *
95b37fcf3Sryker * This library is free for commercial and non-commercial use as long as
105b37fcf3Sryker * the following conditions are aheared to. The following conditions
115b37fcf3Sryker * apply to all code found in this distribution, be it the RC4, RSA,
125b37fcf3Sryker * lhash, DES, etc., code; not just the SSL code. The SSL documentation
135b37fcf3Sryker * included with this distribution is covered by the same copyright terms
145b37fcf3Sryker * except that the holder is Tim Hudson (tjh@cryptsoft.com).
155b37fcf3Sryker *
165b37fcf3Sryker * Copyright remains Eric Young's, and as such any Copyright notices in
175b37fcf3Sryker * the code are not to be removed.
185b37fcf3Sryker * If this package is used in a product, Eric Young should be given attribution
195b37fcf3Sryker * as the author of the parts of the library used.
205b37fcf3Sryker * This can be in the form of a textual message at program startup or
215b37fcf3Sryker * in documentation (online or textual) provided with the package.
225b37fcf3Sryker *
235b37fcf3Sryker * Redistribution and use in source and binary forms, with or without
245b37fcf3Sryker * modification, are permitted provided that the following conditions
255b37fcf3Sryker * are met:
265b37fcf3Sryker * 1. Redistributions of source code must retain the copyright
275b37fcf3Sryker * notice, this list of conditions and the following disclaimer.
285b37fcf3Sryker * 2. Redistributions in binary form must reproduce the above copyright
295b37fcf3Sryker * notice, this list of conditions and the following disclaimer in the
305b37fcf3Sryker * documentation and/or other materials provided with the distribution.
315b37fcf3Sryker * 3. All advertising materials mentioning features or use of this software
325b37fcf3Sryker * must display the following acknowledgement:
335b37fcf3Sryker * "This product includes cryptographic software written by
345b37fcf3Sryker * Eric Young (eay@cryptsoft.com)"
355b37fcf3Sryker * The word 'cryptographic' can be left out if the rouines from the library
365b37fcf3Sryker * being used are not cryptographic related :-).
375b37fcf3Sryker * 4. If you include any Windows specific code (or a derivative thereof) from
385b37fcf3Sryker * the apps directory (application code) you must include an acknowledgement:
395b37fcf3Sryker * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
405b37fcf3Sryker *
415b37fcf3Sryker * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
425b37fcf3Sryker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
435b37fcf3Sryker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
445b37fcf3Sryker * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
455b37fcf3Sryker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
465b37fcf3Sryker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
475b37fcf3Sryker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
485b37fcf3Sryker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
495b37fcf3Sryker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
505b37fcf3Sryker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
515b37fcf3Sryker * SUCH DAMAGE.
525b37fcf3Sryker *
535b37fcf3Sryker * The licence and distribution terms for any publically available version or
545b37fcf3Sryker * derivative of this code cannot be changed. i.e. this code cannot simply be
555b37fcf3Sryker * copied and put under another distribution licence
565b37fcf3Sryker * [including the GNU Public Licence.]
575b37fcf3Sryker */
585b37fcf3Sryker
595b37fcf3Sryker #include <errno.h>
60a8913c44Sjsing #include <stdio.h>
61a8913c44Sjsing #include <string.h>
62a8913c44Sjsing
63913ec974Sbeck #include <openssl/bio.h>
645b37fcf3Sryker
6594b1984eStb #include "bio_local.h"
6694b1984eStb
67c109e398Sbeck static int null_write(BIO *h, const char *buf, int num);
685b37fcf3Sryker static int null_read(BIO *h, char *buf, int size);
69c109e398Sbeck static int null_puts(BIO *h, const char *str);
705b37fcf3Sryker static int null_gets(BIO *h, char *str, int size);
71c109e398Sbeck static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
725b37fcf3Sryker static int null_new(BIO *h);
735b37fcf3Sryker static int null_free(BIO *data);
74c3d505beSjsing
756dc76777Stb static const BIO_METHOD null_method = {
76e402ce74Smiod .type = BIO_TYPE_NULL,
77e402ce74Smiod .name = "NULL",
78e402ce74Smiod .bwrite = null_write,
79e402ce74Smiod .bread = null_read,
80e402ce74Smiod .bputs = null_puts,
81e402ce74Smiod .bgets = null_gets,
82e402ce74Smiod .ctrl = null_ctrl,
83e402ce74Smiod .create = null_new,
84e402ce74Smiod .destroy = null_free
855b37fcf3Sryker };
865b37fcf3Sryker
876dc76777Stb const BIO_METHOD *
BIO_s_null(void)88ae7f143bSderaadt BIO_s_null(void)
895b37fcf3Sryker {
905b37fcf3Sryker return (&null_method);
915b37fcf3Sryker }
92*acf64401Sbeck LCRYPTO_ALIAS(BIO_s_null);
935b37fcf3Sryker
94c3d505beSjsing static int
null_new(BIO * bi)95c3d505beSjsing null_new(BIO *bi)
965b37fcf3Sryker {
975b37fcf3Sryker bi->init = 1;
985b37fcf3Sryker bi->num = 0;
995b37fcf3Sryker bi->ptr = (NULL);
1005b37fcf3Sryker return (1);
1015b37fcf3Sryker }
1025b37fcf3Sryker
103c3d505beSjsing static int
null_free(BIO * a)104c3d505beSjsing null_free(BIO *a)
1055b37fcf3Sryker {
106c3d505beSjsing if (a == NULL)
107c3d505beSjsing return (0);
1085b37fcf3Sryker return (1);
1095b37fcf3Sryker }
1105b37fcf3Sryker
111c3d505beSjsing static int
null_read(BIO * b,char * out,int outl)112c3d505beSjsing null_read(BIO *b, char *out, int outl)
1135b37fcf3Sryker {
1145b37fcf3Sryker return (0);
1155b37fcf3Sryker }
1165b37fcf3Sryker
117c3d505beSjsing static int
null_write(BIO * b,const char * in,int inl)118c3d505beSjsing null_write(BIO *b, const char *in, int inl)
1195b37fcf3Sryker {
1205b37fcf3Sryker return (inl);
1215b37fcf3Sryker }
1225b37fcf3Sryker
123c3d505beSjsing static long
null_ctrl(BIO * b,int cmd,long num,void * ptr)124c3d505beSjsing null_ctrl(BIO *b, int cmd, long num, void *ptr)
1255b37fcf3Sryker {
1265b37fcf3Sryker long ret = 1;
1275b37fcf3Sryker
128c3d505beSjsing switch (cmd) {
1295b37fcf3Sryker case BIO_CTRL_RESET:
1305b37fcf3Sryker case BIO_CTRL_EOF:
1315b37fcf3Sryker case BIO_CTRL_SET:
1325b37fcf3Sryker case BIO_CTRL_SET_CLOSE:
1335b37fcf3Sryker case BIO_CTRL_FLUSH:
1345b37fcf3Sryker case BIO_CTRL_DUP:
1355b37fcf3Sryker ret = 1;
1365b37fcf3Sryker break;
1375b37fcf3Sryker case BIO_CTRL_GET_CLOSE:
1385b37fcf3Sryker case BIO_CTRL_INFO:
1395b37fcf3Sryker case BIO_CTRL_GET:
1405b37fcf3Sryker case BIO_CTRL_PENDING:
1415b37fcf3Sryker case BIO_CTRL_WPENDING:
1425b37fcf3Sryker default:
1435b37fcf3Sryker ret = 0;
1445b37fcf3Sryker break;
1455b37fcf3Sryker }
1465b37fcf3Sryker return (ret);
1475b37fcf3Sryker }
1485b37fcf3Sryker
149c3d505beSjsing static int
null_gets(BIO * bp,char * buf,int size)150c3d505beSjsing null_gets(BIO *bp, char *buf, int size)
1515b37fcf3Sryker {
1525b37fcf3Sryker return (0);
1535b37fcf3Sryker }
1545b37fcf3Sryker
155c3d505beSjsing static int
null_puts(BIO * bp,const char * str)156c3d505beSjsing null_puts(BIO *bp, const char *str)
1575b37fcf3Sryker {
158c3d505beSjsing if (str == NULL)
159c3d505beSjsing return (0);
1605b37fcf3Sryker return (strlen(str));
1615b37fcf3Sryker }
162