1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 13:37:10 +09:00

LibWeb: Implement Web Crypto HMAC algorithm

This commit is contained in:
Jelle Raaijmakers 2024-11-13 15:23:50 +01:00 committed by Andreas Kling
parent 884a4163a0
commit 329cd946ac
Notes: github-actions[bot] 2024-11-14 10:53:12 +00:00
10 changed files with 1064 additions and 13 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -18,6 +19,7 @@ JS_DEFINE_ALLOCATOR(RsaKeyAlgorithm);
JS_DEFINE_ALLOCATOR(RsaHashedKeyAlgorithm);
JS_DEFINE_ALLOCATOR(EcKeyAlgorithm);
JS_DEFINE_ALLOCATOR(AesKeyAlgorithm);
JS_DEFINE_ALLOCATOR(HmacKeyAlgorithm);
template<typename T>
static JS::ThrowCompletionOr<T*> impl_from(JS::VM& vm, StringView Name)
@ -209,4 +211,38 @@ JS_DEFINE_NATIVE_FUNCTION(AesKeyAlgorithm::length_getter)
return length;
}
JS::NonnullGCPtr<HmacKeyAlgorithm> HmacKeyAlgorithm::create(JS::Realm& realm)
{
return realm.create<HmacKeyAlgorithm>(realm);
}
HmacKeyAlgorithm::HmacKeyAlgorithm(JS::Realm& realm)
: KeyAlgorithm(realm)
{
}
void HmacKeyAlgorithm::initialize(JS::Realm& realm)
{
Base::initialize(realm);
define_native_accessor(realm, "hash", hash_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
}
void HmacKeyAlgorithm::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_hash);
}
JS_DEFINE_NATIVE_FUNCTION(HmacKeyAlgorithm::hash_getter)
{
auto* impl = TRY(impl_from<HmacKeyAlgorithm>(vm, "HmacKeyAlgorithm"sv));
return TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->hash(); }));
}
JS_DEFINE_NATIVE_FUNCTION(HmacKeyAlgorithm::length_getter)
{
auto* impl = TRY(impl_from<HmacKeyAlgorithm>(vm, "HmacKeyAlgorithm"sv));
return TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->length(); }));
}
}