/src/openssl/crypto/bio/bf_null.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (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_local.h" |
13 | | #include "internal/cryptlib.h" |
14 | | |
15 | | /* |
16 | | * BIO_put and BIO_get both add to the digest, BIO_gets returns the digest |
17 | | */ |
18 | | |
19 | | static int nullf_write(BIO *h, const char *buf, int num); |
20 | | static int nullf_read(BIO *h, char *buf, int size); |
21 | | static int nullf_puts(BIO *h, const char *str); |
22 | | static int nullf_gets(BIO *h, char *str, int size); |
23 | | static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
24 | | static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); |
25 | | static const BIO_METHOD methods_nullf = { |
26 | | BIO_TYPE_NULL_FILTER, |
27 | | "NULL filter", |
28 | | bwrite_conv, |
29 | | nullf_write, |
30 | | bread_conv, |
31 | | nullf_read, |
32 | | nullf_puts, |
33 | | nullf_gets, |
34 | | nullf_ctrl, |
35 | | NULL, |
36 | | NULL, |
37 | | nullf_callback_ctrl, |
38 | | }; |
39 | | |
40 | | const BIO_METHOD *BIO_f_null(void) |
41 | 0 | { |
42 | 0 | return &methods_nullf; |
43 | 0 | } |
44 | | |
45 | | static int nullf_read(BIO *b, char *out, int outl) |
46 | 0 | { |
47 | 0 | int ret = 0; |
48 | |
|
49 | 0 | if (out == NULL) |
50 | 0 | return 0; |
51 | 0 | if (b->next_bio == NULL) |
52 | 0 | return 0; |
53 | 0 | ret = BIO_read(b->next_bio, out, outl); |
54 | 0 | BIO_clear_retry_flags(b); |
55 | 0 | BIO_copy_next_retry(b); |
56 | 0 | return ret; |
57 | 0 | } |
58 | | |
59 | | static int nullf_write(BIO *b, const char *in, int inl) |
60 | 0 | { |
61 | 0 | int ret = 0; |
62 | |
|
63 | 0 | if ((in == NULL) || (inl <= 0)) |
64 | 0 | return 0; |
65 | 0 | if (b->next_bio == NULL) |
66 | 0 | return 0; |
67 | 0 | ret = BIO_write(b->next_bio, in, inl); |
68 | 0 | BIO_clear_retry_flags(b); |
69 | 0 | BIO_copy_next_retry(b); |
70 | 0 | return ret; |
71 | 0 | } |
72 | | |
73 | | static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr) |
74 | 0 | { |
75 | 0 | long ret; |
76 | |
|
77 | 0 | if (b->next_bio == NULL) |
78 | 0 | return 0; |
79 | 0 | switch (cmd) { |
80 | 0 | case BIO_C_DO_STATE_MACHINE: |
81 | 0 | BIO_clear_retry_flags(b); |
82 | 0 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
83 | 0 | BIO_copy_next_retry(b); |
84 | 0 | break; |
85 | 0 | case BIO_CTRL_DUP: |
86 | 0 | ret = 0L; |
87 | 0 | break; |
88 | 0 | default: |
89 | 0 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
90 | 0 | } |
91 | 0 | return ret; |
92 | 0 | } |
93 | | |
94 | | static long nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) |
95 | 0 | { |
96 | 0 | if (b->next_bio == NULL) |
97 | 0 | return 0; |
98 | 0 | return BIO_callback_ctrl(b->next_bio, cmd, fp); |
99 | 0 | } |
100 | | |
101 | | static int nullf_gets(BIO *bp, char *buf, int size) |
102 | 0 | { |
103 | 0 | if (bp->next_bio == NULL) |
104 | 0 | return 0; |
105 | 0 | return BIO_gets(bp->next_bio, buf, size); |
106 | 0 | } |
107 | | |
108 | | static int nullf_puts(BIO *bp, const char *str) |
109 | 0 | { |
110 | 0 | if (bp->next_bio == NULL) |
111 | 0 | return 0; |
112 | 0 | return BIO_puts(bp->next_bio, str); |
113 | 0 | } |