From 497f3ca0fd48c415a838af3c82a1f9cd5355f4b5 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Thu, 14 Mar 2024 22:11:56 -0600 Subject: [PATCH] LibWeb: Store PBKDF2Params' salt field as a ByteBuffer directly Rather than trying to store a Handle to a WebIDL::BufferSource, let's look ahead to what the spec wants us to do with this field and get a copy of the bytes held by the buffer source right away. --- Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp | 5 ++--- Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 06396655136..4aab6f1aa26 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace Web::Crypto { @@ -216,19 +217,17 @@ PBKDF2Params::~PBKDF2Params() = default; JS::ThrowCompletionOr> PBKDF2Params::from_value(JS::VM& vm, JS::Value value) { - auto& realm = *vm.current_realm(); auto& object = value.as_object(); auto name_value = TRY(object.get("name")); auto name = TRY(name_value.to_string(vm)); auto salt_value = TRY(object.get("salt")); - JS::Handle salt; if (!salt_value.is_object() || !(is(salt_value.as_object()) || is(salt_value.as_object()) || is(salt_value.as_object()))) return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "BufferSource"); - salt = JS::make_handle(vm.heap().allocate(realm, salt_value.as_object())); + auto salt = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(salt_value.as_object())); auto iterations_value = TRY(object.get("iterations")); auto iterations = TRY(iterations_value.to_u32(vm)); diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h index bd99940a29b..00fc33db5f4 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h @@ -39,7 +39,7 @@ struct AlgorithmParams { // https://w3c.github.io/webcrypto/#pbkdf2-params struct PBKDF2Params : public AlgorithmParams { virtual ~PBKDF2Params() override; - PBKDF2Params(String name, JS::Handle salt, u32 iterations, HashAlgorithmIdentifier hash) + PBKDF2Params(String name, ByteBuffer salt, u32 iterations, HashAlgorithmIdentifier hash) : AlgorithmParams(move(name)) , salt(move(salt)) , iterations(iterations) @@ -47,7 +47,7 @@ struct PBKDF2Params : public AlgorithmParams { { } - JS::Handle salt; + ByteBuffer salt; u32 iterations; HashAlgorithmIdentifier hash;