2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2018-02-13 20:51:29 +08:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:20:10 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "bio_local.h"
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-16 06:54:43 +08:00
|
|
|
static int null_write(BIO *h, const char *buf, int num);
|
|
|
|
static int null_read(BIO *h, char *buf, int size);
|
|
|
|
static int null_puts(BIO *h, const char *str);
|
|
|
|
static int null_gets(BIO *h, char *str, int size);
|
|
|
|
static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
|
2016-03-20 00:32:14 +08:00
|
|
|
static const BIO_METHOD null_method = {
|
2015-01-22 11:40:55 +08:00
|
|
|
BIO_TYPE_NULL,
|
|
|
|
"NULL",
|
2016-10-20 22:18:39 +08:00
|
|
|
bwrite_conv,
|
2015-01-22 11:40:55 +08:00
|
|
|
null_write,
|
2016-09-06 00:26:58 +08:00
|
|
|
bread_conv,
|
2015-01-22 11:40:55 +08:00
|
|
|
null_read,
|
|
|
|
null_puts,
|
|
|
|
null_gets,
|
|
|
|
null_ctrl,
|
2018-01-31 22:24:24 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2017-12-18 05:04:48 +08:00
|
|
|
NULL, /* null_callback_ctrl */
|
2015-01-22 11:40:55 +08:00
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2016-03-20 00:32:14 +08:00
|
|
|
const BIO_METHOD *BIO_s_null(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return &null_method;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static int null_read(BIO *b, char *out, int outl)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-16 06:54:43 +08:00
|
|
|
static int null_write(BIO *b, const char *in, int inl)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return inl;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-16 06:54:43 +08:00
|
|
|
static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
long ret = 1;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case BIO_CTRL_RESET:
|
|
|
|
case BIO_CTRL_EOF:
|
|
|
|
case BIO_CTRL_SET:
|
|
|
|
case BIO_CTRL_SET_CLOSE:
|
|
|
|
case BIO_CTRL_FLUSH:
|
|
|
|
case BIO_CTRL_DUP:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_GET_CLOSE:
|
|
|
|
case BIO_CTRL_INFO:
|
|
|
|
case BIO_CTRL_GET:
|
|
|
|
case BIO_CTRL_PENDING:
|
|
|
|
case BIO_CTRL_WPENDING:
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static int null_gets(BIO *bp, char *buf, int size)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-05-16 06:54:43 +08:00
|
|
|
static int null_puts(BIO *bp, const char *str)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
if (str == NULL)
|
2017-10-17 22:04:09 +08:00
|
|
|
return 0;
|
|
|
|
return strlen(str);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|