]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/bio/bss_null.c
Create BIO_read_ex() which handles size_t arguments
[thirdparty/openssl.git] / crypto / bio / bss_null.c
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 /* TODO: Convert to new style read function */
27 bread_conv,
28 null_read,
29 null_puts,
30 null_gets,
31 null_ctrl,
32 null_new,
33 null_free,
34 NULL,
35 };
36
37 const BIO_METHOD *BIO_s_null(void)
38 {
39 return (&null_method);
40 }
41
42 static int null_new(BIO *bi)
43 {
44 bi->init = 1;
45 bi->num = 0;
46 bi->ptr = (NULL);
47 return (1);
48 }
49
50 static int null_free(BIO *a)
51 {
52 if (a == NULL)
53 return (0);
54 return (1);
55 }
56
57 static int null_read(BIO *b, char *out, int outl)
58 {
59 return (0);
60 }
61
62 static int null_write(BIO *b, const char *in, int inl)
63 {
64 return (inl);
65 }
66
67 static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
68 {
69 long ret = 1;
70
71 switch (cmd) {
72 case BIO_CTRL_RESET:
73 case BIO_CTRL_EOF:
74 case BIO_CTRL_SET:
75 case BIO_CTRL_SET_CLOSE:
76 case BIO_CTRL_FLUSH:
77 case BIO_CTRL_DUP:
78 ret = 1;
79 break;
80 case BIO_CTRL_GET_CLOSE:
81 case BIO_CTRL_INFO:
82 case BIO_CTRL_GET:
83 case BIO_CTRL_PENDING:
84 case BIO_CTRL_WPENDING:
85 default:
86 ret = 0;
87 break;
88 }
89 return (ret);
90 }
91
92 static int null_gets(BIO *bp, char *buf, int size)
93 {
94 return (0);
95 }
96
97 static int null_puts(BIO *bp, const char *str)
98 {
99 if (str == NULL)
100 return (0);
101 return (strlen(str));
102 }