Просмотр исходного кода

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.
Andrew Kaster 1 год назад
Родитель
Сommit
497f3ca0fd

+ 2 - 3
Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp

@@ -16,6 +16,7 @@
 #include <LibWeb/Crypto/CryptoAlgorithms.h>
 #include <LibWeb/Crypto/KeyAlgorithms.h>
 #include <LibWeb/Crypto/SubtleCrypto.h>
+#include <LibWeb/WebIDL/AbstractOperations.h>
 
 namespace Web::Crypto {
 
@@ -216,19 +217,17 @@ PBKDF2Params::~PBKDF2Params() = default;
 
 JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> 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<WebIDL::BufferSource> salt;
 
     if (!salt_value.is_object() || !(is<JS::TypedArrayBase>(salt_value.as_object()) || is<JS::ArrayBuffer>(salt_value.as_object()) || is<JS::DataView>(salt_value.as_object())))
         return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource");
 
-    salt = JS::make_handle(vm.heap().allocate<WebIDL::BufferSource>(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));

+ 2 - 2
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<WebIDL::BufferSource> 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<WebIDL::BufferSource> salt;
+    ByteBuffer salt;
     u32 iterations;
     HashAlgorithmIdentifier hash;