AK: Add a public helper to count the decoded length of a Base64 string

This commit is contained in:
Timothy Flynn 2024-09-01 11:49:23 -04:00 committed by Andreas Kling
parent 41e14e3fc3
commit 35d8e7e63f
Notes: github-actions[bot] 2024-09-03 15:47:24 +00:00
2 changed files with 8 additions and 1 deletions

View file

@ -12,10 +12,15 @@
namespace AK { namespace AK {
size_t size_required_to_decode_base64(StringView input)
{
return simdutf::maximal_binary_length_from_base64(input.characters_without_null_termination(), input.length());
}
static ErrorOr<ByteBuffer> decode_base64_impl(StringView input, simdutf::base64_options options) static ErrorOr<ByteBuffer> decode_base64_impl(StringView input, simdutf::base64_options options)
{ {
ByteBuffer output; ByteBuffer output;
TRY(output.try_resize(simdutf::maximal_binary_length_from_base64(input.characters_without_null_termination(), input.length()))); TRY(output.try_resize(size_required_to_decode_base64(input)));
auto result = simdutf::base64_to_binary( auto result = simdutf::base64_to_binary(
input.characters_without_null_termination(), input.characters_without_null_termination(),

View file

@ -13,6 +13,8 @@
namespace AK { namespace AK {
size_t size_required_to_decode_base64(StringView);
ErrorOr<ByteBuffer> decode_base64(StringView); ErrorOr<ByteBuffer> decode_base64(StringView);
ErrorOr<ByteBuffer> decode_base64url(StringView); ErrorOr<ByteBuffer> decode_base64url(StringView);