2016-05-17 18:52:22 +00:00
|
|
|
/*
|
2018-02-13 12:51:29 +00:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 03:40:55 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* 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 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2016-03-22 09:21:29 +00:00
|
|
|
#include "bio_lcl.h"
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
|
|
|
|
*/
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-05-15 22:54:43 +00:00
|
|
|
static int nullf_write(BIO *h, const char *buf, int num);
|
|
|
|
static int nullf_read(BIO *h, char *buf, int size);
|
|
|
|
static int nullf_puts(BIO *h, const char *str);
|
|
|
|
static int nullf_gets(BIO *h, char *str, int size);
|
|
|
|
static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
|
2017-12-15 18:33:48 +00:00
|
|
|
static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
|
2016-03-19 16:32:14 +00:00
|
|
|
static const BIO_METHOD methods_nullf = {
|
2015-01-22 03:40:55 +00:00
|
|
|
BIO_TYPE_NULL_FILTER,
|
|
|
|
"NULL filter",
|
2016-10-20 14:18:39 +00:00
|
|
|
/* TODO: Convert to new style write function */
|
|
|
|
bwrite_conv,
|
2015-01-22 03:40:55 +00:00
|
|
|
nullf_write,
|
2016-09-05 16:26:58 +00:00
|
|
|
/* TODO: Convert to new style read function */
|
|
|
|
bread_conv,
|
2015-01-22 03:40:55 +00:00
|
|
|
nullf_read,
|
|
|
|
nullf_puts,
|
|
|
|
nullf_gets,
|
|
|
|
nullf_ctrl,
|
2018-01-31 14:24:24 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-01-22 03:40:55 +00:00
|
|
|
nullf_callback_ctrl,
|
|
|
|
};
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-03-19 16:32:14 +00:00
|
|
|
const BIO_METHOD *BIO_f_null(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-10-17 14:04:09 +00:00
|
|
|
return &methods_nullf;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static int nullf_read(BIO *b, char *out, int outl)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (out == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (b->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
ret = BIO_read(b->next_bio, out, outl);
|
|
|
|
BIO_clear_retry_flags(b);
|
|
|
|
BIO_copy_next_retry(b);
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-05-15 22:54:43 +00:00
|
|
|
static int nullf_write(BIO *b, const char *in, int inl)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if ((in == NULL) || (inl <= 0))
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (b->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
ret = BIO_write(b->next_bio, in, inl);
|
|
|
|
BIO_clear_retry_flags(b);
|
|
|
|
BIO_copy_next_retry(b);
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-05-15 22:54:43 +00:00
|
|
|
static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
if (b->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case BIO_C_DO_STATE_MACHINE:
|
|
|
|
BIO_clear_retry_flags(b);
|
|
|
|
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
|
|
|
BIO_copy_next_retry(b);
|
|
|
|
break;
|
|
|
|
case BIO_CTRL_DUP:
|
|
|
|
ret = 0L;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
|
|
|
}
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2017-12-15 18:33:48 +00:00
|
|
|
static long nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
long ret = 1;
|
|
|
|
|
|
|
|
if (b->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
switch (cmd) {
|
|
|
|
default:
|
|
|
|
ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-17 14:04:09 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2000-02-20 23:43:02 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static int nullf_gets(BIO *bp, char *buf, int size)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
if (bp->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
|
|
|
return BIO_gets(bp->next_bio, buf, size);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-05-15 22:54:43 +00:00
|
|
|
static int nullf_puts(BIO *bp, const char *str)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
if (bp->next_bio == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
|
|
|
return BIO_puts(bp->next_bio, str);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|