1BIO_S_MEM(3)                        OpenSSL                       BIO_S_MEM(3)
2
3
4

NAME

6       BIO_s_secmem, BIO_s_mem, BIO_set_mem_eof_return, BIO_get_mem_data,
7       BIO_set_mem_buf, BIO_get_mem_ptr, BIO_new_mem_buf - memory BIO
8

SYNOPSIS

10        #include <openssl/bio.h>
11
12        const BIO_METHOD *BIO_s_mem(void);
13        const BIO_METHOD *BIO_s_secmem(void);
14
15        BIO_set_mem_eof_return(BIO *b, int v)
16        long BIO_get_mem_data(BIO *b, char **pp)
17        BIO_set_mem_buf(BIO *b, BUF_MEM *bm, int c)
18        BIO_get_mem_ptr(BIO *b, BUF_MEM **pp)
19
20        BIO *BIO_new_mem_buf(const void *buf, int len);
21

DESCRIPTION

23       BIO_s_mem() returns the memory BIO method function.
24
25       A memory BIO is a source/sink BIO which uses memory for its I/O. Data
26       written to a memory BIO is stored in a BUF_MEM structure which is
27       extended as appropriate to accommodate the stored data.
28
29       BIO_s_secmem() is like BIO_s_mem() except that the secure heap is used
30       for buffer storage.
31
32       Any data written to a memory BIO can be recalled by reading from it.
33       Unless the memory BIO is read only any data read from it is deleted
34       from the BIO.
35
36       Memory BIOs support BIO_gets() and BIO_puts().
37
38       If the BIO_CLOSE flag is set when a memory BIO is freed then the
39       underlying BUF_MEM structure is also freed.
40
41       Calling BIO_reset() on a read write memory BIO clears any data in it if
42       the flag BIO_FLAGS_NONCLEAR_RST is not set. On a read only BIO or if
43       the flag BIO_FLAGS_NONCLEAR_RST is set it restores the BIO to its
44       original state and the data can be read again.
45
46       BIO_eof() is true if no data is in the BIO.
47
48       BIO_ctrl_pending() returns the number of bytes currently stored.
49
50       BIO_set_mem_eof_return() sets the behaviour of memory BIO b when it is
51       empty. If the v is zero then an empty memory BIO will return EOF (that
52       is it will return zero and BIO_should_retry(b) will be false. If v is
53       non zero then it will return v when it is empty and it will set the
54       read retry flag (that is BIO_read_retry(b) is true). To avoid ambiguity
55       with a normal positive return value v should be set to a negative
56       value, typically -1.
57
58       BIO_get_mem_data() sets *pp to a pointer to the start of the memory
59       BIOs data and returns the total amount of data available. It is
60       implemented as a macro.
61
62       BIO_set_mem_buf() sets the internal BUF_MEM structure to bm and sets
63       the close flag to c, that is c should be either BIO_CLOSE or
64       BIO_NOCLOSE.  It is a macro.
65
66       BIO_get_mem_ptr() places the underlying BUF_MEM structure in *pp. It is
67       a macro.
68
69       BIO_new_mem_buf() creates a memory BIO using len bytes of data at buf,
70       if len is -1 then the buf is assumed to be nul terminated and its
71       length is determined by strlen. The BIO is set to a read only state and
72       as a result cannot be written to. This is useful when some data needs
73       to be made available from a static area of memory in the form of a BIO.
74       The supplied data is read directly from the supplied buffer: it is not
75       copied first, so the supplied area of memory must be unchanged until
76       the BIO is freed.
77

NOTES

79       Writes to memory BIOs will always succeed if memory is available: that
80       is their size can grow indefinitely.
81
82       Every read from a read write memory BIO will remove the data just read
83       with an internal copy operation, if a BIO contains a lot of data and it
84       is read in small chunks the operation can be very slow. The use of a
85       read only memory BIO avoids this problem. If the BIO must be read write
86       then adding a buffering BIO to the chain will speed up the process.
87
88       Calling BIO_set_mem_buf() on a BIO created with BIO_new_secmem() will
89       give undefined results, including perhaps a program crash.
90

BUGS

92       There should be an option to set the maximum size of a memory BIO.
93

EXAMPLE

95       Create a memory BIO and write some data to it:
96
97        BIO *mem = BIO_new(BIO_s_mem());
98
99        BIO_puts(mem, "Hello World\n");
100
101       Create a read only memory BIO:
102
103        char data[] = "Hello World";
104        BIO *mem = BIO_new_mem_buf(data, -1);
105
106       Extract the BUF_MEM structure from a memory BIO and then free up the
107       BIO:
108
109        BUF_MEM *bptr;
110
111        BIO_get_mem_ptr(mem, &bptr);
112        BIO_set_close(mem, BIO_NOCLOSE); /* So BIO_free() leaves BUF_MEM alone */
113        BIO_free(mem);
114

RETURN VALUES

116       BIO_s_mem() and BIO_s_secmem() return a valid memory BIO_METHOD
117       structure.
118
119       BIO_set_mem_eof_return(), BIO_get_mem_data(), BIO_set_mem_buf() and
120       BIO_get_mem_ptr() return 1 on success or a value which is less than or
121       equal to 0 if an error occurred.
122
123       BIO_new_mem_buf() returns a valid BIO structure on success or NULL on
124       error.
125
127       Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
128
129       Licensed under the OpenSSL license (the "License").  You may not use
130       this file except in compliance with the License.  You can obtain a copy
131       in the file LICENSE in the source distribution or at
132       <https://www.openssl.org/source/license.html>.
133
134
135
1361.1.1                             2018-09-11                      BIO_S_MEM(3)
Impressum