]>
Commit | Line | Data |
---|---|---|
b1322259 | 1 | /* |
6738bf14 | 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. |
0f113f3e | 3 | * |
09abbca1 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
11 | #include <errno.h> | |
706457b7 | 12 | #include "bio_local.h" |
b39fc560 | 13 | #include "internal/cryptlib.h" |
d02b48c6 | 14 | |
0f113f3e MC |
15 | /* |
16 | * BIO_put and BIO_get both add to the digest, BIO_gets returns the digest | |
17 | */ | |
d02b48c6 | 18 | |
0e1c0612 UM |
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); | |
fce78bd4 | 24 | static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); |
04f6b0fd | 25 | static const BIO_METHOD methods_nullf = { |
0f113f3e MC |
26 | BIO_TYPE_NULL_FILTER, |
27 | "NULL filter", | |
3befffa3 MC |
28 | /* TODO: Convert to new style write function */ |
29 | bwrite_conv, | |
0f113f3e | 30 | nullf_write, |
d07aee2c MC |
31 | /* TODO: Convert to new style read function */ |
32 | bread_conv, | |
0f113f3e MC |
33 | nullf_read, |
34 | nullf_puts, | |
35 | nullf_gets, | |
36 | nullf_ctrl, | |
94f1c937 RL |
37 | NULL, |
38 | NULL, | |
0f113f3e MC |
39 | nullf_callback_ctrl, |
40 | }; | |
d02b48c6 | 41 | |
04f6b0fd | 42 | const BIO_METHOD *BIO_f_null(void) |
0f113f3e | 43 | { |
26a7d938 | 44 | return &methods_nullf; |
0f113f3e | 45 | } |
d02b48c6 | 46 | |
6b691a5c | 47 | static int nullf_read(BIO *b, char *out, int outl) |
0f113f3e MC |
48 | { |
49 | int ret = 0; | |
50 | ||
51 | if (out == NULL) | |
26a7d938 | 52 | return 0; |
0f113f3e | 53 | if (b->next_bio == NULL) |
26a7d938 | 54 | return 0; |
0f113f3e MC |
55 | ret = BIO_read(b->next_bio, out, outl); |
56 | BIO_clear_retry_flags(b); | |
57 | BIO_copy_next_retry(b); | |
26a7d938 | 58 | return ret; |
0f113f3e | 59 | } |
d02b48c6 | 60 | |
0e1c0612 | 61 | static int nullf_write(BIO *b, const char *in, int inl) |
0f113f3e MC |
62 | { |
63 | int ret = 0; | |
64 | ||
65 | if ((in == NULL) || (inl <= 0)) | |
26a7d938 | 66 | return 0; |
0f113f3e | 67 | if (b->next_bio == NULL) |
26a7d938 | 68 | return 0; |
0f113f3e MC |
69 | ret = BIO_write(b->next_bio, in, inl); |
70 | BIO_clear_retry_flags(b); | |
71 | BIO_copy_next_retry(b); | |
26a7d938 | 72 | return ret; |
0f113f3e | 73 | } |
d02b48c6 | 74 | |
0e1c0612 | 75 | static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr) |
0f113f3e MC |
76 | { |
77 | long ret; | |
78 | ||
79 | if (b->next_bio == NULL) | |
26a7d938 | 80 | return 0; |
0f113f3e MC |
81 | switch (cmd) { |
82 | case BIO_C_DO_STATE_MACHINE: | |
83 | BIO_clear_retry_flags(b); | |
84 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | |
85 | BIO_copy_next_retry(b); | |
86 | break; | |
87 | case BIO_CTRL_DUP: | |
88 | ret = 0L; | |
89 | break; | |
90 | default: | |
91 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); | |
92 | } | |
26a7d938 | 93 | return ret; |
0f113f3e | 94 | } |
d02b48c6 | 95 | |
fce78bd4 | 96 | static long nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) |
0f113f3e MC |
97 | { |
98 | long ret = 1; | |
99 | ||
100 | if (b->next_bio == NULL) | |
26a7d938 | 101 | return 0; |
0f113f3e MC |
102 | switch (cmd) { |
103 | default: | |
104 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); | |
105 | break; | |
106 | } | |
26a7d938 | 107 | return ret; |
0f113f3e | 108 | } |
d3442bc7 | 109 | |
6b691a5c | 110 | static int nullf_gets(BIO *bp, char *buf, int size) |
0f113f3e MC |
111 | { |
112 | if (bp->next_bio == NULL) | |
26a7d938 K |
113 | return 0; |
114 | return BIO_gets(bp->next_bio, buf, size); | |
0f113f3e | 115 | } |
d02b48c6 | 116 | |
0e1c0612 | 117 | static int nullf_puts(BIO *bp, const char *str) |
0f113f3e MC |
118 | { |
119 | if (bp->next_bio == NULL) | |
26a7d938 K |
120 | return 0; |
121 | return BIO_puts(bp->next_bio, str); | |
0f113f3e | 122 | } |