diff options
Diffstat (limited to 'src/lib/libcrypto/man/BIO_s_mem.3')
-rw-r--r-- | src/lib/libcrypto/man/BIO_s_mem.3 | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/BIO_s_mem.3 b/src/lib/libcrypto/man/BIO_s_mem.3 new file mode 100644 index 0000000000..a37b4bff98 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_mem.3 | |||
@@ -0,0 +1,190 @@ | |||
1 | .Dd $Mdocdate: February 16 2015 $ | ||
2 | .Dt BIO_S_MEM 3 | ||
3 | .Os | ||
4 | .Sh NAME | ||
5 | .Nm BIO_s_mem , | ||
6 | .Nm BIO_set_mem_eof_return , | ||
7 | .Nm BIO_get_mem_data , | ||
8 | .Nm BIO_set_mem_buf , | ||
9 | .Nm BIO_get_mem_ptr , | ||
10 | .Nm BIO_new_mem_buf | ||
11 | .Nd memory BIO | ||
12 | .Sh SYNOPSIS | ||
13 | .In openssl/bio.h | ||
14 | .Ft BIO_METHOD * | ||
15 | .Fo BIO_s_mem | ||
16 | .Fa "void" | ||
17 | .Fc | ||
18 | .Ft long | ||
19 | .Fo BIO_set_mem_eof_return | ||
20 | .Fa "BIO *b" | ||
21 | .Fa "int v" | ||
22 | .Fc | ||
23 | .Ft long | ||
24 | .Fo BIO_get_mem_data | ||
25 | .Fa "BIO *b" | ||
26 | .Fa "char **pp" | ||
27 | .Fc | ||
28 | .Ft long | ||
29 | .Fo BIO_set_mem_buf | ||
30 | .Fa "BIO *b" | ||
31 | .Fa "BUF_MEM *bm" | ||
32 | .Fa "int c" | ||
33 | .Fc | ||
34 | .Ft long | ||
35 | .Fo BIO_get_mem_ptr | ||
36 | .Fa "BIO *b" | ||
37 | .Fa "BUF_MEM **pp" | ||
38 | .Fc | ||
39 | .Ft BIO * | ||
40 | .Fo BIO_new_mem_buf | ||
41 | .Fa "void *buf" | ||
42 | .Fa "int len" | ||
43 | .Fc | ||
44 | .Sh DESCRIPTION | ||
45 | .Fn BIO_s_mem | ||
46 | returns the memory BIO method function. | ||
47 | .Pp | ||
48 | A memory BIO is a source/sink BIO which uses memory for its I/O. | ||
49 | Data written to a memory BIO is stored in a | ||
50 | .Vt BUF_MEM | ||
51 | structure which is extended as appropriate to accommodate the stored data. | ||
52 | .Pp | ||
53 | Any data written to a memory BIO can be recalled by reading from it. | ||
54 | Unless the memory BIO is read only, | ||
55 | any data read from it is deleted from the BIO. | ||
56 | .Pp | ||
57 | Memory BIOs support | ||
58 | .Xr BIO_gets 3 | ||
59 | and | ||
60 | .Xr BIO_puts 3 . | ||
61 | .Pp | ||
62 | If the | ||
63 | .Dv BIO_CLOSE | ||
64 | flag is set when a memory BIO is freed, the underlying | ||
65 | .Dv BUF_MEM | ||
66 | structure is also freed. | ||
67 | .Pp | ||
68 | Calling | ||
69 | .Xr BIO_reset 3 | ||
70 | on a read/write memory BIO clears any data in it. | ||
71 | On a read only BIO it restores the BIO to its original state | ||
72 | and the read only data can be read again. | ||
73 | .Pp | ||
74 | .Xr BIO_eof 3 | ||
75 | is true if no data is in the BIO. | ||
76 | .Pp | ||
77 | .Xr BIO_ctrl_pending 3 | ||
78 | returns the number of bytes currently stored. | ||
79 | .Pp | ||
80 | .Xr BIO_set_mem_eof_return 3 | ||
81 | sets the behaviour of memory BIO | ||
82 | .Fa b | ||
83 | when it is empty. | ||
84 | If | ||
85 | .Fa v | ||
86 | is zero, then an empty memory BIO will return EOF: | ||
87 | It will return zero and | ||
88 | .Fn BIO_should_retry | ||
89 | will be false. | ||
90 | If | ||
91 | .Fa v | ||
92 | is non-zero then it will return | ||
93 | .Fa v | ||
94 | when it is empty and it will set the read retry flag: | ||
95 | .Fn BIO_read_retry | ||
96 | is true. | ||
97 | To avoid ambiguity with a normal positive return value | ||
98 | .Fa v | ||
99 | should be set to a negative value, typically -1. | ||
100 | .Pp | ||
101 | .Fn BIO_get_mem_data | ||
102 | sets | ||
103 | .Fa pp | ||
104 | to a pointer to the start of the memory BIO's data | ||
105 | and returns the total amount of data available. | ||
106 | It is implemented as a macro. | ||
107 | .Pp | ||
108 | .Fn BIO_set_mem_buf | ||
109 | sets the internal BUF_MEM structure to | ||
110 | .Fa bm | ||
111 | and sets the close flag to | ||
112 | .Fa c , | ||
113 | that is | ||
114 | .Fa c | ||
115 | should be either | ||
116 | .Dv BIO_CLOSE | ||
117 | or | ||
118 | .Dv BIO_NOCLOSE . | ||
119 | .Fn BIO_set_mem_buf | ||
120 | is a macro. | ||
121 | .Pp | ||
122 | .Fn BIO_get_mem_ptr | ||
123 | places the underlying | ||
124 | .Vt BUF_MEM | ||
125 | structure in | ||
126 | .Fa pp . | ||
127 | It is a macro. | ||
128 | .Pp | ||
129 | .Fn BIO_new_mem_buf | ||
130 | creates a memory BIO using | ||
131 | .Fa len | ||
132 | bytes of data at | ||
133 | .Fa buf . | ||
134 | If | ||
135 | .Fa len | ||
136 | is -1, then | ||
137 | .Fa buf | ||
138 | is assumed to be NUL terminated and its length is determined by | ||
139 | .Xr strlen 3 . | ||
140 | The BIO is set to a read only state and as a result cannot be written to. | ||
141 | This is useful when some data needs to be made available | ||
142 | from a static area of memory in the form of a BIO. | ||
143 | The supplied data is read directly from the supplied buffer: | ||
144 | it is | ||
145 | .Em not | ||
146 | copied first, so the supplied area of memory must be unchanged | ||
147 | until the BIO is freed. | ||
148 | .Sh NOTES | ||
149 | Writes to memory BIOs will always succeed if memory is available: | ||
150 | their size can grow indefinitely. | ||
151 | .Pp | ||
152 | Every read from a read/write memory BIO will remove the data just read | ||
153 | with an internal copy operation. | ||
154 | If a BIO contains a lot of data and it is read in small chunks, | ||
155 | the operation can be very slow. | ||
156 | The use of a read only memory BIO avoids this problem. | ||
157 | If the BIO must be read/write then adding a buffering BIO | ||
158 | to the chain will speed up the process. | ||
159 | .Sh EXAMPLES | ||
160 | Create a memory BIO and write some data to it: | ||
161 | .Bd -literal -offset indent | ||
162 | BIO *mem = BIO_new(BIO_s_mem()); | ||
163 | BIO_puts(mem, "Hello World\en"); | ||
164 | .Ed | ||
165 | .Pp | ||
166 | Create a read only memory BIO: | ||
167 | .Bd -literal -offset indent | ||
168 | char data[] = "Hello World"; | ||
169 | BIO *mem; | ||
170 | mem = BIO_new_mem_buf(data, -1); | ||
171 | .Ed | ||
172 | .Pp | ||
173 | Extract the | ||
174 | .Vt BUF_MEM | ||
175 | structure from a memory BIO and then free up the BIO: | ||
176 | .Bd -literal -offset indent | ||
177 | BUF_MEM *bptr; | ||
178 | BIO_get_mem_ptr(mem, &bptr); | ||
179 | /* Make sure BIO_free() leaves BUF_MEM alone. */ | ||
180 | BIO_set_close(mem, BIO_NOCLOSE); | ||
181 | BIO_free(mem); | ||
182 | .Ed | ||
183 | .Sh BUGS | ||
184 | There should be an option to set the maximum size of a memory BIO. | ||
185 | .Pp | ||
186 | There should be a way to "rewind" a read/write BIO without destroying | ||
187 | its contents. | ||
188 | .Pp | ||
189 | The copying operation should not occur after every small read | ||
190 | of a large BIO to improve efficiency. | ||