From 35d8e7e63f90ef5c1710108a52ad829e24f630bd Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 1 Sep 2024 11:49:23 -0400 Subject: [PATCH] AK: Add a public helper to count the decoded length of a Base64 string --- AK/Base64.cpp | 7 ++++++- AK/Base64.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/AK/Base64.cpp b/AK/Base64.cpp index 8c1806f9fc8..c4155e12fcf 100644 --- a/AK/Base64.cpp +++ b/AK/Base64.cpp @@ -12,10 +12,15 @@ 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 decode_base64_impl(StringView input, simdutf::base64_options options) { 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( input.characters_without_null_termination(), diff --git a/AK/Base64.h b/AK/Base64.h index 51db98ab664..f448a0f9657 100644 --- a/AK/Base64.h +++ b/AK/Base64.h @@ -13,6 +13,8 @@ namespace AK { +size_t size_required_to_decode_base64(StringView); + ErrorOr decode_base64(StringView); ErrorOr decode_base64url(StringView);