mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
AK: Compute the exact size of decoded Base64 strings
This commit is contained in:
parent
754ff41b9c
commit
4ecf4c7617
1 changed files with 8 additions and 4 deletions
|
@ -15,7 +15,14 @@ namespace AK {
|
||||||
|
|
||||||
size_t calculate_base64_decoded_length(StringView input)
|
size_t calculate_base64_decoded_length(StringView input)
|
||||||
{
|
{
|
||||||
return input.length() * 3 / 4;
|
auto length = input.length() * 3 / 4;
|
||||||
|
|
||||||
|
if (input.ends_with("="sv))
|
||||||
|
--length;
|
||||||
|
if (input.ends_with("=="sv))
|
||||||
|
--length;
|
||||||
|
|
||||||
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t calculate_base64_encoded_length(ReadonlyBytes input)
|
size_t calculate_base64_encoded_length(ReadonlyBytes input)
|
||||||
|
@ -70,9 +77,6 @@ static ErrorOr<ByteBuffer> decode_base64_impl(StringView input, ReadonlySpan<i16
|
||||||
output[output_offset++] = ((in2 & 0x3) << 6) | in3;
|
output[output_offset++] = ((in2 & 0x3) << 6) | in3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_offset < output.size())
|
|
||||||
output.trim(output_offset, false);
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue