Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error (#25834)

* std: Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error

* std: update doc comment of Base64DecoderWithIgnore.calcSizeUpperBound
This commit is contained in:
marximimus 2025-11-07 08:16:34 +01:00 committed by GitHub
parent 40132af3ad
commit 2e8f8afc83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -313,9 +313,9 @@ pub const Base64DecoderWithIgnore = struct {
return result;
}
/// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding.
/// `InvalidPadding` is returned if the input length is not valid.
pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) Error!usize {
/// Return the maximum possible decoded size for a given input length - The actual length may be
/// less if the input includes padding or ignored characters.
pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) usize {
var result = source_len / 4 * 3;
if (decoder_with_ignore.decoder.pad_char == null) {
const leftover = source_len % 4;
@ -521,7 +521,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
{
const decoder_ignore_nothing = codecs.decoderWithIgnore("");
var buffer: [0x100]u8 = undefined;
const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
const decoded = buffer[0..decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
try testing.expect(written <= decoded.len);
try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
@ -531,7 +531,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {
const decoder_ignore_space = codecs.decoderWithIgnore(" ");
var buffer: [0x100]u8 = undefined;
const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
const decoded = buffer[0..decoder_ignore_space.calcSizeUpperBound(encoded.len)];
const written = try decoder_ignore_space.decode(decoded, encoded);
try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
}