Lines Matching +full:internal +full:- +full:mem

2  * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
31 #define sEOF "-EOF" /* '-' as in PEM and MIME boundaries */
34 #define EOF_RETURN (-1729) /* Distinct from -1, etc., internal results */
43 #define NVARPAD (NVAR * NPAD - NPAD + 1)
65 static int memout(BIO *mem, char c, int llen, int *pos) in memout() argument
67 if (BIO_write(mem, &c, 1) != 1) in memout()
72 if (BIO_write(mem, &c, 1) != 1) in memout()
78 /* Encode and append one 6-bit slice, randomly prepending some whitespace */
79 static int memoutws(BIO *mem, char c, unsigned wscnt, unsigned llen, int *pos) in memoutws() argument
83 && memout(mem, ' ', llen, pos) == 0) in memoutws()
85 return memout(mem, c, llen, pos); in memoutws()
94 int trunc, unsigned llen, unsigned wscnt, BIO *mem) in encode() argument
105 return BIO_write(mem, encoded, elen) == elen; in encode()
108 /* Encode full 3-octet groups */ in encode()
112 if (memoutws(mem, b64[v >> 18], wscnt, llen, &pos) == 0 in encode()
113 || memoutws(mem, b64[(v >> 12) & 0x3f], wscnt, llen, &pos) == 0 in encode()
114 || memoutws(mem, b64[(v >> 6) & 0x3f], wscnt, llen, &pos) == 0 in encode()
115 || memoutws(mem, b64[v & 0x3f], wscnt, llen, &pos) == 0) in encode()
118 buflen -= 3; in encode()
125 if (memoutws(mem, b64[(v >> 10) & 0x3f], wscnt, llen, &pos) == 0 in encode()
126 || memoutws(mem, b64[(v >> 4) & 0x3f], wscnt, llen, &pos) == 0 in encode()
127 || memoutws(mem, b64[(v & 0xf) << 2], wscnt, llen, &pos) == 0 in encode()
128 || memoutws(mem, '=', wscnt, llen, &pos) == 0) in encode()
133 if (memoutws(mem, b64[v >> 2], wscnt, llen, &pos) == 0 in encode()
134 || memoutws(mem, b64[(v & 0x3) << 4], wscnt, llen, &pos) == 0 in encode()
135 || memoutws(mem, '=', wscnt, llen, &pos) == 0 in encode()
136 || memoutws(mem, '=', wscnt, llen, &pos) == 0) in encode()
140 while (trunc-- > 0) in encode()
141 if (memoutws(mem, 'A', wscnt, llen, &pos) == 0) in encode()
145 if (pos > 0 && BIO_write(mem, &nl, 1) != 1) in encode()
160 BIO *mem = BIO_new(BIO_s_mem()); in genb64() local
162 if (mem == NULL) in genb64()
163 return -1; in genb64()
165 if ((*prefix && (BIO_write(mem, prefix, preflen) != preflen in genb64()
166 || BIO_write(mem, &newline, 1) != 1)) in genb64()
167 || encode(buf, buflen, encoded, trunc, llen, wscnt, mem) <= 0 in genb64()
168 || (*suffix && (BIO_write(mem, suffix, sufflen) != sufflen in genb64()
169 || BIO_write(mem, &newline, 1) != 1))) { in genb64()
170 BIO_free(mem); in genb64()
171 return -1; in genb64()
175 BIO_get_mem_ptr(mem, &bptr); in genb64()
176 *out = bptr->data; in genb64()
177 outlen = bptr->length; in genb64()
178 bptr->data = NULL; in genb64()
179 (void) BIO_set_close(mem, BIO_NOCLOSE); in genb64()
180 BIO_free(mem); in genb64()
198 * Pre-encoded data always encodes NUL octets. If all we care about is the in test_bio_base64_run()
201 if (t->encoded != NULL) in test_bio_base64_run()
202 raw = OPENSSL_zalloc(t->bytes); in test_bio_base64_run()
204 raw = genbytes(t->bytes); in test_bio_base64_run()
206 if (raw == NULL && t->bytes > 0) { in test_bio_base64_run()
208 return -1; in test_bio_base64_run()
211 out_len = t->bytes + 1024; in test_bio_base64_run()
216 return -1; in test_bio_base64_run()
219 elen = genb64(t->prefix, t->suffix, raw, t->bytes, t->trunc, t->encoded, in test_bio_base64_run()
226 return -1; in test_bio_base64_run()
228 if (t->retry) in test_bio_base64_run()
239 if (t->retry) in test_bio_base64_run()
245 if (t->no_nl) in test_bio_base64_run()
253 BIO_write(bio, encoded + n1, elen - n1); in test_bio_base64_run()
255 n2 = BIO_read(b64, out + n, out_len - n); in test_bio_base64_run()
263 /* Turn retry-related negative results to normal (0) EOF */ in test_bio_base64_run()
268 if (t->retry) in test_bio_base64_run()
273 ret = BIO_read(b64, out + n, out_len - n); in test_bio_base64_run()
277 ret = -1; in test_bio_base64_run()
283 * - truncated groups, in test_bio_base64_run()
284 * - non-base64 suffixes (other than soft EOF) for non-empty or oneline in test_bio_base64_run()
286 * - non-base64 prefixes in NO_NL mode in test_bio_base64_run()
290 if (t->trunc > 0 in test_bio_base64_run()
291 || ((t->bytes > 0 || t->no_nl) && *t->suffix && *t->suffix != '-') in test_bio_base64_run()
292 || (t->no_nl && *t->prefix)) { in test_bio_base64_run()
293 if ((ret = ret < 0 ? 0 : -1) != 0) in test_bio_base64_run()
294 TEST_error("Final read result was non-negative"); in test_bio_base64_run()
296 || n != (int) t->bytes in test_bio_base64_run()
299 ret = -1; in test_bio_base64_run()
318 int extra = t->no_nl ? 64 : 0; in generic_case()
329 if (*t->prefix) in generic_case()
330 fprintf(stderr, ", prefix='%s'", t->prefix); in generic_case()
331 if (t->encoded) in generic_case()
332 fprintf(stderr, ", data='%s'", t->encoded); in generic_case()
334 fprintf(stderr, ", datalen=%u", t->bytes); in generic_case()
335 if (t->trunc) in generic_case()
336 fprintf(stderr, ", trunc=%d", t->trunc); in generic_case()
337 if (*t->suffix) in generic_case()
338 fprintf(stderr, ", suffix='%s'", t->suffix); in generic_case()
341 if (t->retry) in generic_case()
343 if (t->no_nl) in generic_case()
349 if (t->encoded) in generic_case()
356 if (*llen > t->bytes + (t->bytes >> 1)) in generic_case()
365 return i - *q * m; in quotrem()
394 t.trunc = padcase - 2; in test_bio_base64_generated()
397 if (padcase != 0 && (*t.suffix && *t.suffix != '-')) { in test_bio_base64_generated()
418 /* 9 bytes of skipped non-base64 input + newline */ in test_bio_base64_corner_case_bug()
438 gunk[sizeof(gunk) - 1] = '\0'; in setup_tests()
443 * - both empty in setup_tests()
444 * - short junk prefix in setup_tests()
445 * - long gunk prefix (> internal BIO 1k buffer size), in setup_tests()
446 * - soft EOF suffix in setup_tests()
447 * - junk suffix (expect to detect an error) in setup_tests()
465 * - Non-retriable underlying BIO in setup_tests()
466 * - Retriable underlying BIO in setup_tests()
475 numidx = NLEN * (NVAR * NPAD - NPAD + 1) * 2 * 2; in setup_tests()