From 3ef65e45d720f70ab5e19dc76226969a0d76d0ab Mon Sep 17 00:00:00 2001 From: rmg-x Date: Sat, 16 Aug 2025 10:35:02 -0500 Subject: [PATCH] LibWeb/Crypto: Avoid heap allocation for AesGcm tag lengths --- Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index fc2ad5af087..8c6e83119dc 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -3156,12 +3156,12 @@ WebIDL::ExceptionOr> AesGcm::encrypt(AlgorithmParams co // 4. If the tagLength member of normalizedAlgorithm is not present: Let tagLength be 128. auto tag_length = 0; - auto to_compare_against = Vector { 32, 64, 96, 104, 112, 120, 128 }; + auto constexpr valid_tag_lengths = Array { 32, 64, 96, 104, 112, 120, 128 }; if (!normalized_algorithm.tag_length.has_value()) tag_length = 128; // If the tagLength member of normalizedAlgorithm is one of 32, 64, 96, 104, 112, 120 or 128: Let tagLength be equal to the tagLength member of normalizedAlgorithm - else if (to_compare_against.contains_slow(normalized_algorithm.tag_length.value())) + else if (valid_tag_lengths.contains_slow(normalized_algorithm.tag_length.value())) tag_length = normalized_algorithm.tag_length.value(); // Otherwise: throw an OperationError. @@ -3198,12 +3198,12 @@ WebIDL::ExceptionOr> AesGcm::decrypt(AlgorithmParams co // 1. If the tagLength member of normalizedAlgorithm is not present: Let tagLength be 128. u32 tag_length = 0; - auto to_compare_against = Vector { 32, 64, 96, 104, 112, 120, 128 }; + auto constexpr valid_tag_lengths = Array { 32, 64, 96, 104, 112, 120, 128 }; if (!normalized_algorithm.tag_length.has_value()) tag_length = 128; // If the tagLength member of normalizedAlgorithm is one of 32, 64, 96, 104, 112, 120 or 128: Let tagLength be equal to the tagLength member of normalizedAlgorithm - else if (to_compare_against.contains_slow(normalized_algorithm.tag_length.value())) + else if (valid_tag_lengths.contains_slow(normalized_algorithm.tag_length.value())) tag_length = normalized_algorithm.tag_length.value(); // Otherwise: throw an OperationError.