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