/src/openssl41/crypto/evp/bio_b64.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1995-2026 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 "internal/cryptlib.h" |
13 | | #include <openssl/buffer.h> |
14 | | #include <openssl/evp.h> |
15 | | #include "internal/bio.h" |
16 | | #include "crypto/evp.h" |
17 | | |
18 | | static int b64_write(BIO *h, const char *buf, int num); |
19 | | static int b64_read(BIO *h, char *buf, int size); |
20 | | static int b64_puts(BIO *h, const char *str); |
21 | | static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
22 | | static int b64_new(BIO *h); |
23 | | static int b64_free(BIO *data); |
24 | | static long b64_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); |
25 | 206k | #define B64_BLOCK_SIZE 1024 |
26 | | #define B64_BLOCK_SIZE2 768 |
27 | 0 | #define B64_NONE 0 |
28 | 4.60k | #define B64_ENCODE 1 |
29 | 4.28M | #define B64_DECODE 2 |
30 | | |
31 | | typedef struct b64_struct { |
32 | | /* |
33 | | * BIO *bio; moved to the BIO structure |
34 | | */ |
35 | | int buf_len; |
36 | | int buf_off; |
37 | | int tmp_len; /* used to find the start when decoding */ |
38 | | int tmp_nl; /* If true, scan until '\n' */ |
39 | | int encode; |
40 | | int start; /* have we started decoding yet? */ |
41 | | int cont; /* <= 0 when finished */ |
42 | | EVP_ENCODE_CTX *base64; |
43 | | unsigned char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE) + 10]; |
44 | | unsigned char tmp[B64_BLOCK_SIZE]; |
45 | | unsigned char *encoded_buf; |
46 | | size_t encoded_buf_len; |
47 | | } BIO_B64_CTX; |
48 | | |
49 | | static const BIO_METHOD methods_b64 = { |
50 | | BIO_TYPE_BASE64, |
51 | | "base64 encoding", |
52 | | bwrite_conv, |
53 | | b64_write, |
54 | | bread_conv, |
55 | | b64_read, |
56 | | b64_puts, |
57 | | NULL, /* b64_gets, */ |
58 | | b64_ctrl, |
59 | | b64_new, |
60 | | b64_free, |
61 | | b64_callback_ctrl, |
62 | | }; |
63 | | |
64 | | const BIO_METHOD *BIO_f_base64(void) |
65 | 12.5k | { |
66 | 12.5k | return &methods_b64; |
67 | 12.5k | } |
68 | | |
69 | | static int b64_new(BIO *bi) |
70 | 12.5k | { |
71 | 12.5k | BIO_B64_CTX *ctx; |
72 | | |
73 | 12.5k | if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL) |
74 | 0 | return 0; |
75 | | |
76 | 12.5k | ctx->cont = 1; |
77 | 12.5k | ctx->start = 1; |
78 | 12.5k | ctx->encoded_buf = NULL; |
79 | 12.5k | ctx->encoded_buf_len = 0; |
80 | 12.5k | ctx->base64 = EVP_ENCODE_CTX_new(); |
81 | 12.5k | if (ctx->base64 == NULL) { |
82 | 0 | OPENSSL_free(ctx); |
83 | 0 | return 0; |
84 | 0 | } |
85 | | |
86 | 12.5k | BIO_set_data(bi, ctx); |
87 | 12.5k | BIO_set_init(bi, 1); |
88 | | |
89 | 12.5k | return 1; |
90 | 12.5k | } |
91 | | |
92 | | static int b64_free(BIO *a) |
93 | 12.5k | { |
94 | 12.5k | BIO_B64_CTX *ctx; |
95 | | |
96 | 12.5k | if (a == NULL) |
97 | 0 | return 0; |
98 | | |
99 | 12.5k | ctx = BIO_get_data(a); |
100 | 12.5k | if (ctx == NULL) |
101 | 0 | return 0; |
102 | | |
103 | 12.5k | OPENSSL_free(ctx->encoded_buf); |
104 | 12.5k | ctx->encoded_buf = NULL; |
105 | 12.5k | ctx->encoded_buf_len = 0; |
106 | 12.5k | EVP_ENCODE_CTX_free(ctx->base64); |
107 | 12.5k | OPENSSL_free(ctx); |
108 | 12.5k | BIO_set_data(a, NULL); |
109 | 12.5k | BIO_set_init(a, 0); |
110 | | |
111 | 12.5k | return 1; |
112 | 12.5k | } |
113 | | |
114 | | /* |
115 | | * Unless `BIO_FLAGS_BASE64_NO_NL` is set, this BIO ignores leading lines that |
116 | | * aren't exclusively composed of valid Base64 characters (followed by <CRLF> |
117 | | * or <LF>). Once a valid Base64 line is found, `ctx->start` is set to 0 and |
118 | | * lines are processed until EOF or the first line that contains invalid Base64 |
119 | | * characters. In a nod to PEM, lines that start with a '-' (hyphen) are |
120 | | * treated as a soft EOF, rather than an error. |
121 | | */ |
122 | | static int b64_read(BIO *b, char *out, int outl) |
123 | 4.27M | { |
124 | 4.27M | int ret = 0, i, ii, j, k, x, n, num, ret_code; |
125 | 4.27M | BIO_B64_CTX *ctx; |
126 | 4.27M | unsigned char *p, *q; |
127 | 4.27M | BIO *next; |
128 | | |
129 | 4.27M | if (out == NULL) |
130 | 0 | return 0; |
131 | 4.27M | ctx = (BIO_B64_CTX *)BIO_get_data(b); |
132 | | |
133 | 4.27M | next = BIO_next(b); |
134 | 4.27M | if (ctx == NULL || next == NULL) |
135 | 0 | return 0; |
136 | | |
137 | 4.27M | BIO_clear_retry_flags(b); |
138 | | |
139 | 4.27M | if (ctx->encode != B64_DECODE) { |
140 | 7.31k | ctx->encode = B64_DECODE; |
141 | 7.31k | ctx->buf_len = 0; |
142 | 7.31k | ctx->buf_off = 0; |
143 | 7.31k | ctx->tmp_len = 0; |
144 | 7.31k | EVP_DecodeInit(ctx->base64); |
145 | 7.31k | } |
146 | | |
147 | | /* First check if there are buffered bytes already decoded */ |
148 | 4.27M | if (ctx->buf_len > 0) { |
149 | 4.26M | if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) { |
150 | 0 | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
151 | 0 | return -1; |
152 | 0 | } |
153 | 4.26M | i = ctx->buf_len - ctx->buf_off; |
154 | 4.26M | if (i > outl) |
155 | 4.23M | i = outl; |
156 | 4.26M | if (!ossl_assert(ctx->buf_off + i < (int)sizeof(ctx->buf))) { |
157 | 0 | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
158 | 0 | return -1; |
159 | 0 | } |
160 | 4.26M | memcpy(out, &(ctx->buf[ctx->buf_off]), i); |
161 | 4.26M | ret = i; |
162 | 4.26M | out += i; |
163 | 4.26M | outl -= i; |
164 | 4.26M | ctx->buf_off += i; |
165 | 4.26M | if (ctx->buf_len == ctx->buf_off) { |
166 | 32.8k | ctx->buf_len = 0; |
167 | 32.8k | ctx->buf_off = 0; |
168 | 32.8k | } |
169 | 4.26M | } |
170 | | |
171 | | /* Restore any non-retriable error condition (ctx->cont < 0) */ |
172 | 4.27M | ret_code = ctx->cont < 0 ? ctx->cont : 0; |
173 | | |
174 | | /* |
175 | | * At this point, we have room of outl bytes and an either an empty buffer, |
176 | | * or outl == 0, so we'll attempt to read in some more. |
177 | | */ |
178 | 4.35M | while (outl > 0) { |
179 | 78.4k | int again = ctx->cont; |
180 | | |
181 | 78.4k | if (again <= 0) |
182 | 814 | break; |
183 | | |
184 | 77.6k | i = BIO_read(next, &(ctx->tmp[ctx->tmp_len]), |
185 | 77.6k | B64_BLOCK_SIZE - ctx->tmp_len); |
186 | | |
187 | 77.6k | if (i <= 0) { |
188 | 4.20k | ret_code = i; |
189 | | |
190 | | /* Should we continue next time we are called? */ |
191 | 4.20k | if (!BIO_should_retry(next)) { |
192 | | /* Incomplete final Base64 chunk in the decoder is an error */ |
193 | 4.20k | if (ctx->tmp_len == 0) { |
194 | 1.45k | if (EVP_DecodeFinal(ctx->base64, NULL, &num) < 0) |
195 | 353 | ret_code = -1; |
196 | 1.45k | EVP_DecodeInit(ctx->base64); |
197 | 1.45k | } |
198 | 4.20k | ctx->cont = ret_code; |
199 | 4.20k | } |
200 | 4.20k | if (ctx->tmp_len == 0) |
201 | 1.45k | break; |
202 | | /* Fall through and process what we have */ |
203 | 2.75k | i = 0; |
204 | | /* But don't loop to top-up even if the buffer is not full! */ |
205 | 2.75k | again = 0; |
206 | 2.75k | } |
207 | | |
208 | 76.1k | i += ctx->tmp_len; |
209 | 76.1k | ctx->tmp_len = i; |
210 | | |
211 | | /* |
212 | | * We need to scan, a line at a time until we have a valid line if we |
213 | | * are starting. |
214 | | */ |
215 | 76.1k | if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) != 0) { |
216 | 165 | ctx->tmp_len = 0; |
217 | 75.9k | } else if (ctx->start) { |
218 | 12.4k | q = p = ctx->tmp; |
219 | 12.4k | num = 0; |
220 | 5.64M | for (j = 0; j < i; j++) { |
221 | 5.64M | if (*(q++) != '\n') |
222 | 5.30M | continue; |
223 | | |
224 | | /* |
225 | | * due to a previous very long line, we need to keep on |
226 | | * scanning for a '\n' before we even start looking for |
227 | | * base64 encoded stuff. |
228 | | */ |
229 | 332k | if (ctx->tmp_nl) { |
230 | 969 | p = q; |
231 | 969 | ctx->tmp_nl = 0; |
232 | 969 | continue; |
233 | 969 | } |
234 | | |
235 | 331k | k = EVP_DecodeUpdate(ctx->base64, ctx->buf, &num, p, (int)(q - p)); |
236 | 331k | EVP_DecodeInit(ctx->base64); |
237 | 331k | if (k <= 0 && num == 0) { |
238 | 324k | p = q; |
239 | 324k | continue; |
240 | 324k | } |
241 | | |
242 | 6.75k | ctx->start = 0; |
243 | 6.75k | if (p != ctx->tmp) { |
244 | 475 | i -= (int)(p - ctx->tmp); |
245 | 279k | for (x = 0; x < i; x++) |
246 | 278k | ctx->tmp[x] = p[x]; |
247 | 475 | } |
248 | 6.75k | break; |
249 | 331k | } |
250 | | |
251 | | /* we fell off the end without starting */ |
252 | 12.4k | if (ctx->start) { |
253 | | /* |
254 | | * Is this is one long chunk?, if so, keep on reading until a |
255 | | * new line. |
256 | | */ |
257 | 5.67k | if (p == ctx->tmp) { |
258 | | /* Check buffer full */ |
259 | 1.91k | if (i == B64_BLOCK_SIZE) { |
260 | 1.56k | ctx->tmp_nl = 1; |
261 | 1.56k | ctx->tmp_len = 0; |
262 | 1.56k | } |
263 | 3.76k | } else if (p != q) { |
264 | | /* Retain partial line at end of buffer */ |
265 | 2.96k | n = (int)(q - p); |
266 | 1.49M | for (ii = 0; ii < n; ii++) |
267 | 1.49M | ctx->tmp[ii] = p[ii]; |
268 | 2.96k | ctx->tmp_len = n; |
269 | 2.96k | } else { |
270 | | /* All we have is newline terminated non-start data */ |
271 | 805 | ctx->tmp_len = 0; |
272 | 805 | } |
273 | | /* |
274 | | * Try to read more if possible, otherwise we can't make |
275 | | * progress unless the underlying BIO is retriable and may |
276 | | * produce more data next time we're called. |
277 | | */ |
278 | 5.67k | if (again > 0) |
279 | 5.44k | continue; |
280 | 229 | else |
281 | 229 | break; |
282 | 6.75k | } else { |
283 | 6.75k | ctx->tmp_len = 0; |
284 | 6.75k | } |
285 | 63.5k | } else if (i < B64_BLOCK_SIZE && again > 0) { |
286 | | /* |
287 | | * If buffer isn't full and we can retry then restart to read in |
288 | | * more data. |
289 | | */ |
290 | 2.52k | continue; |
291 | 2.52k | } |
292 | | |
293 | 67.9k | i = EVP_DecodeUpdate(ctx->base64, ctx->buf, &ctx->buf_len, |
294 | 67.9k | ctx->tmp, i); |
295 | 67.9k | ctx->tmp_len = 0; |
296 | | /* |
297 | | * If eof or an error was signalled, then the condition |
298 | | * 'ctx->cont <= 0' will prevent b64_read() from reading |
299 | | * more data on subsequent calls. This assignment was |
300 | | * deleted accidentally in commit 5562cfaca4f3. |
301 | | */ |
302 | 67.9k | ctx->cont = i; |
303 | | |
304 | 67.9k | ctx->buf_off = 0; |
305 | 67.9k | if (i < 0) { |
306 | 329 | ret_code = ctx->start ? 0 : i; |
307 | 329 | ctx->buf_len = 0; |
308 | 329 | break; |
309 | 329 | } |
310 | | |
311 | 67.6k | if (ctx->buf_len <= outl) |
312 | 31.4k | i = ctx->buf_len; |
313 | 36.1k | else |
314 | 36.1k | i = outl; |
315 | | |
316 | 67.6k | memcpy(out, ctx->buf, i); |
317 | 67.6k | ret += i; |
318 | 67.6k | ctx->buf_off = i; |
319 | 67.6k | if (ctx->buf_off == ctx->buf_len) { |
320 | 31.4k | ctx->buf_len = 0; |
321 | 31.4k | ctx->buf_off = 0; |
322 | 31.4k | } |
323 | 67.6k | outl -= i; |
324 | 67.6k | out += i; |
325 | 67.6k | } |
326 | 4.27M | BIO_copy_next_retry(b); |
327 | 4.27M | return ret == 0 ? ret_code : ret; |
328 | 4.27M | } |
329 | | |
330 | | static int b64_write(BIO *b, const char *in, int inl) |
331 | | { |
332 | | int ret = 0; |
333 | | int n; |
334 | | int i; |
335 | | BIO_B64_CTX *ctx; |
336 | | BIO *next; |
337 | | size_t encoded_length; |
338 | | unsigned char *encoded; |
339 | | int n_bytes_enc; |
340 | | |
341 | | ctx = (BIO_B64_CTX *)BIO_get_data(b); |
342 | | next = BIO_next(b); |
343 | | if (ctx == NULL || next == NULL) |
344 | | return 0; |
345 | | |
346 | | BIO_clear_retry_flags(b); |
347 | | |
348 | | if (ctx->encode != B64_ENCODE) { |
349 | | ctx->encode = B64_ENCODE; |
350 | | ctx->buf_len = 0; |
351 | | ctx->buf_off = 0; |
352 | | ctx->tmp_len = 0; |
353 | | EVP_EncodeInit(ctx->base64); |
354 | | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) |
355 | | evp_encode_ctx_set_flags(ctx->base64, EVP_ENCODE_CTX_NO_NEWLINES); |
356 | | } |
357 | | if (!ossl_assert(ctx->buf_off < (int)sizeof(ctx->buf))) { |
358 | | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
359 | | return -1; |
360 | | } |
361 | | if (!ossl_assert(ctx->buf_len <= (int)sizeof(ctx->buf))) { |
362 | | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
363 | | return -1; |
364 | | } |
365 | | if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) { |
366 | | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
367 | | return -1; |
368 | | } |
369 | | n = ctx->buf_len - ctx->buf_off; |
370 | | while (n > 0) { |
371 | | i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n); |
372 | | if (i <= 0) { |
373 | | BIO_copy_next_retry(b); |
374 | | return i; |
375 | | } |
376 | | ctx->buf_off += i; |
377 | | if (!ossl_assert(ctx->buf_off <= (int)sizeof(ctx->buf))) { |
378 | | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
379 | | return -1; |
380 | | } |
381 | | if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) { |
382 | | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
383 | | return -1; |
384 | | } |
385 | | n -= i; |
386 | | } |
387 | | /* at this point all pending data has been written */ |
388 | | ctx->buf_off = 0; |
389 | | ctx->buf_len = 0; |
390 | | |
391 | | if (in == NULL || inl <= 0) |
392 | | return 0; |
393 | | |
394 | | encoded_length = EVP_ENCODE_LENGTH(inl); |
395 | | |
396 | | if (encoded_length > SIZE_MAX / 2) { |
397 | | ERR_raise(ERR_LIB_BIO, BIO_R_LENGTH_TOO_LONG); |
398 | | return -1; |
399 | | } |
400 | | |
401 | | if (ctx->encoded_buf == NULL || encoded_length > ctx->encoded_buf_len) { |
402 | | OPENSSL_free(ctx->encoded_buf); |
403 | | ctx->encoded_buf = OPENSSL_malloc(encoded_length); |
404 | | if (ctx->encoded_buf == NULL) { |
405 | | ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); |
406 | | return -1; |
407 | | } |
408 | | ctx->encoded_buf_len = encoded_length; |
409 | | } |
410 | | |
411 | | encoded = ctx->encoded_buf; |
412 | | |
413 | | if (encoded == NULL) { |
414 | | ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); |
415 | | return -1; |
416 | | } |
417 | | n_bytes_enc = 0; |
418 | | if (!EVP_EncodeUpdate(ctx->base64, encoded, &n_bytes_enc, |
419 | | (unsigned char *)in, inl)) { |
420 | | return -1; |
421 | | } |
422 | | ret += inl; |
423 | | i = BIO_write(next, encoded, n_bytes_enc); |
424 | | if (i <= 0) |
425 | | BIO_copy_next_retry(b); |
426 | | return ret; |
427 | | } |
428 | | |
429 | | static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) |
430 | 15.7k | { |
431 | 15.7k | BIO_B64_CTX *ctx; |
432 | 15.7k | long ret = 1; |
433 | 15.7k | int i; |
434 | 15.7k | BIO *next; |
435 | | |
436 | 15.7k | ctx = (BIO_B64_CTX *)BIO_get_data(b); |
437 | 15.7k | next = BIO_next(b); |
438 | | /* |
439 | | * If there is no ctx or no next BIO, BIO_read() returns 0, which means EOF. |
440 | | * BIO_eof() should return 1 in this case. |
441 | | */ |
442 | 15.7k | if (ctx == NULL || next == NULL) |
443 | 0 | return cmd == BIO_CTRL_EOF; |
444 | | |
445 | 15.7k | switch (cmd) { |
446 | 0 | case BIO_CTRL_RESET: |
447 | 0 | ctx->cont = 1; |
448 | 0 | ctx->start = 1; |
449 | 0 | ctx->encode = B64_NONE; |
450 | 0 | ret = BIO_ctrl(next, cmd, num, ptr); |
451 | 0 | break; |
452 | 1.73k | case BIO_CTRL_EOF: /* More to read */ |
453 | 1.73k | if (ctx->cont <= 0) |
454 | 1.73k | ret = 1; |
455 | 0 | else |
456 | 0 | ret = BIO_ctrl(next, cmd, num, ptr); |
457 | 1.73k | break; |
458 | 0 | case BIO_CTRL_WPENDING: /* More to write in buffer */ |
459 | 0 | if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) { |
460 | 0 | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
461 | 0 | return -1; |
462 | 0 | } |
463 | 0 | ret = ctx->buf_len - ctx->buf_off; |
464 | 0 | if (ret == 0 && ctx->encode != B64_NONE |
465 | 0 | && EVP_ENCODE_CTX_num(ctx->base64) != 0) |
466 | 0 | ret = 1; |
467 | 0 | else if (ret <= 0) |
468 | 0 | ret = BIO_ctrl(next, cmd, num, ptr); |
469 | 0 | break; |
470 | 0 | case BIO_CTRL_PENDING: /* More to read in buffer */ |
471 | 0 | if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) { |
472 | 0 | ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR); |
473 | 0 | return -1; |
474 | 0 | } |
475 | 0 | ret = ctx->buf_len - ctx->buf_off; |
476 | 0 | if (ret <= 0) |
477 | 0 | ret = BIO_ctrl(next, cmd, num, ptr); |
478 | 0 | break; |
479 | 4.60k | case BIO_CTRL_FLUSH: |
480 | 4.60k | if (ctx->encode == B64_ENCODE) { |
481 | | /* do a final write */ |
482 | 0 | again: |
483 | 0 | while (ctx->buf_len != ctx->buf_off) { |
484 | 0 | i = b64_write(b, NULL, 0); |
485 | 0 | if (i < 0) |
486 | 0 | return i; |
487 | 0 | } |
488 | 0 | if (EVP_ENCODE_CTX_num(ctx->base64) != 0) { |
489 | 0 | ctx->buf_off = 0; |
490 | 0 | EVP_EncodeFinal(ctx->base64, ctx->buf, &(ctx->buf_len)); |
491 | | /* push out the bytes */ |
492 | 0 | goto again; |
493 | 0 | } |
494 | 0 | } |
495 | | /* Finally flush the underlying BIO */ |
496 | 4.60k | BIO_clear_retry_flags(b); |
497 | 4.60k | ret = BIO_ctrl(next, cmd, num, ptr); |
498 | 4.60k | BIO_copy_next_retry(b); |
499 | 4.60k | break; |
500 | | |
501 | 0 | case BIO_C_DO_STATE_MACHINE: |
502 | 0 | BIO_clear_retry_flags(b); |
503 | 0 | ret = BIO_ctrl(next, cmd, num, ptr); |
504 | 0 | BIO_copy_next_retry(b); |
505 | 0 | break; |
506 | | |
507 | 0 | case BIO_CTRL_DUP: |
508 | 0 | break; |
509 | 0 | case BIO_CTRL_INFO: |
510 | 0 | case BIO_CTRL_GET: |
511 | 0 | case BIO_CTRL_SET: |
512 | 9.36k | default: |
513 | 9.36k | ret = BIO_ctrl(next, cmd, num, ptr); |
514 | 9.36k | break; |
515 | 15.7k | } |
516 | 15.7k | return ret; |
517 | 15.7k | } |
518 | | |
519 | | static long b64_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) |
520 | 0 | { |
521 | 0 | BIO *next = BIO_next(b); |
522 | |
|
523 | 0 | if (next == NULL) |
524 | 0 | return 0; |
525 | | |
526 | 0 | return BIO_callback_ctrl(next, cmd, fp); |
527 | 0 | } |
528 | | |
529 | | static int b64_puts(BIO *b, const char *str) |
530 | 0 | { |
531 | 0 | size_t len = strlen(str); |
532 | |
|
533 | 0 | if (len > INT_MAX) |
534 | 0 | return -1; |
535 | 0 | return b64_write(b, str, (int)len); |
536 | 0 | } |