1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdio.h> 11e1051a39Sopenharmony_ci#include <errno.h> 12e1051a39Sopenharmony_ci#include "bio_local.h" 13e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 14e1051a39Sopenharmony_ci 15e1051a39Sopenharmony_cistatic int null_write(BIO *h, const char *buf, int num); 16e1051a39Sopenharmony_cistatic int null_read(BIO *h, char *buf, int size); 17e1051a39Sopenharmony_cistatic int null_puts(BIO *h, const char *str); 18e1051a39Sopenharmony_cistatic int null_gets(BIO *h, char *str, int size); 19e1051a39Sopenharmony_cistatic long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); 20e1051a39Sopenharmony_cistatic const BIO_METHOD null_method = { 21e1051a39Sopenharmony_ci BIO_TYPE_NULL, 22e1051a39Sopenharmony_ci "NULL", 23e1051a39Sopenharmony_ci bwrite_conv, 24e1051a39Sopenharmony_ci null_write, 25e1051a39Sopenharmony_ci bread_conv, 26e1051a39Sopenharmony_ci null_read, 27e1051a39Sopenharmony_ci null_puts, 28e1051a39Sopenharmony_ci null_gets, 29e1051a39Sopenharmony_ci null_ctrl, 30e1051a39Sopenharmony_ci NULL, 31e1051a39Sopenharmony_ci NULL, 32e1051a39Sopenharmony_ci NULL, /* null_callback_ctrl */ 33e1051a39Sopenharmony_ci}; 34e1051a39Sopenharmony_ci 35e1051a39Sopenharmony_ciconst BIO_METHOD *BIO_s_null(void) 36e1051a39Sopenharmony_ci{ 37e1051a39Sopenharmony_ci return &null_method; 38e1051a39Sopenharmony_ci} 39e1051a39Sopenharmony_ci 40e1051a39Sopenharmony_cistatic int null_read(BIO *b, char *out, int outl) 41e1051a39Sopenharmony_ci{ 42e1051a39Sopenharmony_ci return 0; 43e1051a39Sopenharmony_ci} 44e1051a39Sopenharmony_ci 45e1051a39Sopenharmony_cistatic int null_write(BIO *b, const char *in, int inl) 46e1051a39Sopenharmony_ci{ 47e1051a39Sopenharmony_ci return inl; 48e1051a39Sopenharmony_ci} 49e1051a39Sopenharmony_ci 50e1051a39Sopenharmony_cistatic long null_ctrl(BIO *b, int cmd, long num, void *ptr) 51e1051a39Sopenharmony_ci{ 52e1051a39Sopenharmony_ci long ret = 1; 53e1051a39Sopenharmony_ci 54e1051a39Sopenharmony_ci switch (cmd) { 55e1051a39Sopenharmony_ci case BIO_CTRL_RESET: 56e1051a39Sopenharmony_ci case BIO_CTRL_EOF: 57e1051a39Sopenharmony_ci case BIO_CTRL_SET: 58e1051a39Sopenharmony_ci case BIO_CTRL_SET_CLOSE: 59e1051a39Sopenharmony_ci case BIO_CTRL_FLUSH: 60e1051a39Sopenharmony_ci case BIO_CTRL_DUP: 61e1051a39Sopenharmony_ci ret = 1; 62e1051a39Sopenharmony_ci break; 63e1051a39Sopenharmony_ci case BIO_CTRL_GET_CLOSE: 64e1051a39Sopenharmony_ci case BIO_CTRL_INFO: 65e1051a39Sopenharmony_ci case BIO_CTRL_GET: 66e1051a39Sopenharmony_ci case BIO_CTRL_PENDING: 67e1051a39Sopenharmony_ci case BIO_CTRL_WPENDING: 68e1051a39Sopenharmony_ci default: 69e1051a39Sopenharmony_ci ret = 0; 70e1051a39Sopenharmony_ci break; 71e1051a39Sopenharmony_ci } 72e1051a39Sopenharmony_ci return ret; 73e1051a39Sopenharmony_ci} 74e1051a39Sopenharmony_ci 75e1051a39Sopenharmony_cistatic int null_gets(BIO *bp, char *buf, int size) 76e1051a39Sopenharmony_ci{ 77e1051a39Sopenharmony_ci return 0; 78e1051a39Sopenharmony_ci} 79e1051a39Sopenharmony_ci 80e1051a39Sopenharmony_cistatic int null_puts(BIO *bp, const char *str) 81e1051a39Sopenharmony_ci{ 82e1051a39Sopenharmony_ci if (str == NULL) 83e1051a39Sopenharmony_ci return 0; 84e1051a39Sopenharmony_ci return strlen(str); 85e1051a39Sopenharmony_ci} 86