From 1b3e1dfd01a136b386dfbff49b4918cbbf0c9ebd Mon Sep 17 00:00:00 2001 From: devgianlu Date: Thu, 26 Dec 2024 18:08:37 +0100 Subject: [PATCH] LibWeb: Always return a `KeyAlgorithm` from `RsaHashedKeyAlgorithm` The spec never mentions the possibility for the `hash` member of `RsaHashedKeyAlgorithm` to be a string, it should be a `KeyAlgorithm` object containing a `name` string member. Does not fix any WPT test now, but will eventually. Spec: https://w3c.github.io/webcrypto/#dfn-RsaHashedKeyAlgorithm --- Libraries/LibWeb/Crypto/KeyAlgorithms.cpp | 5 ++++- .../Crypto/SubtleCrypto-import-rsaoaep-minimal_jwk.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/Crypto/KeyAlgorithms.cpp b/Libraries/LibWeb/Crypto/KeyAlgorithms.cpp index 999d6d73af3e7..bf645b0907ffa 100644 --- a/Libraries/LibWeb/Crypto/KeyAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/KeyAlgorithms.cpp @@ -179,7 +179,10 @@ JS_DEFINE_NATIVE_FUNCTION(RsaHashedKeyAlgorithm::hash_getter) auto hash = TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->hash(); })); return hash.visit( [&](String const& hash_string) -> JS::Value { - return JS::PrimitiveString::create(vm, hash_string); + auto& realm = *vm.current_realm(); + auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); + MUST(object->create_data_property("name", JS::PrimitiveString::create(vm, hash_string))); + return object; }, [&](GC::Root const& hash) -> JS::Value { return hash; diff --git a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-import-rsaoaep-minimal_jwk.html b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-import-rsaoaep-minimal_jwk.html index 617d75bb0c686..1d41902bd626f 100644 --- a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-import-rsaoaep-minimal_jwk.html +++ b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-import-rsaoaep-minimal_jwk.html @@ -16,7 +16,7 @@ ); println(key.extractable); println(key.algorithm.name); - println(key.algorithm.hash); + println(key.algorithm.hash.name); println(key.algorithm.publicExponent); done(); });