LibWeb: Implement WebCrypto AES-CBC importKey operation

This alone lets us pass around 40 WPT tests:
WebCryptoAPI/import_export/symmetric_importKey.https.any
This commit is contained in:
Ben Wiederhake 2024-10-25 05:58:30 +02:00 committed by Andreas Kling
parent 92d4cb7b09
commit 6f88376e24
Notes: github-actions[bot] 2024-10-26 15:51:42 +00:00
5 changed files with 262 additions and 2 deletions

View file

@ -17,6 +17,7 @@ JS_DEFINE_ALLOCATOR(KeyAlgorithm);
JS_DEFINE_ALLOCATOR(RsaKeyAlgorithm);
JS_DEFINE_ALLOCATOR(RsaHashedKeyAlgorithm);
JS_DEFINE_ALLOCATOR(EcKeyAlgorithm);
JS_DEFINE_ALLOCATOR(AesKeyAlgorithm);
template<typename T>
static JS::ThrowCompletionOr<T*> impl_from(JS::VM& vm, StringView Name)
@ -183,4 +184,29 @@ JS_DEFINE_NATIVE_FUNCTION(RsaHashedKeyAlgorithm::hash_getter)
});
}
JS::NonnullGCPtr<AesKeyAlgorithm> AesKeyAlgorithm::create(JS::Realm& realm)
{
return realm.heap().allocate<AesKeyAlgorithm>(realm, realm);
}
AesKeyAlgorithm::AesKeyAlgorithm(JS::Realm& realm)
: KeyAlgorithm(realm)
, m_length(0)
{
}
void AesKeyAlgorithm::initialize(JS::Realm& realm)
{
Base::initialize(realm);
define_native_accessor(realm, "length", length_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
}
JS_DEFINE_NATIVE_FUNCTION(AesKeyAlgorithm::length_getter)
{
auto* impl = TRY(impl_from<AesKeyAlgorithm>(vm, "AesKeyAlgorithm"sv));
auto length = TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->length(); }));
return length;
}
}