LibWeb: Implement generateKey for ECDSA

This commit is contained in:
stelar7 2024-03-27 01:27:42 +01:00 committed by Andrew Kaster
commit 41449814db
Notes: sideshowbarker 2024-07-17 07:06:47 +09:00
5 changed files with 201 additions and 0 deletions

View file

@ -16,6 +16,7 @@ namespace Web::Crypto {
JS_DEFINE_ALLOCATOR(KeyAlgorithm);
JS_DEFINE_ALLOCATOR(RsaKeyAlgorithm);
JS_DEFINE_ALLOCATOR(RsaHashedKeyAlgorithm);
JS_DEFINE_ALLOCATOR(EcKeyAlgorithm);
template<typename T>
static JS::ThrowCompletionOr<T*> impl_from(JS::VM& vm, StringView Name)
@ -119,6 +120,34 @@ JS_DEFINE_NATIVE_FUNCTION(RsaKeyAlgorithm::public_exponent_getter)
return impl->public_exponent();
}
JS::NonnullGCPtr<EcKeyAlgorithm> EcKeyAlgorithm::create(JS::Realm& realm)
{
return realm.heap().allocate<EcKeyAlgorithm>(realm, realm);
}
EcKeyAlgorithm::EcKeyAlgorithm(JS::Realm& realm)
: KeyAlgorithm(realm)
{
}
void EcKeyAlgorithm::initialize(JS::Realm& realm)
{
Base::initialize(realm);
define_native_accessor(realm, "namedCurve", named_curve_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
}
JS_DEFINE_NATIVE_FUNCTION(EcKeyAlgorithm::named_curve_getter)
{
auto* impl = TRY(impl_from<EcKeyAlgorithm>(vm, "EcKeyAlgorithm"sv));
return JS::PrimitiveString::create(vm, impl->named_curve());
}
void EcKeyAlgorithm::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
}
JS::NonnullGCPtr<RsaHashedKeyAlgorithm> RsaHashedKeyAlgorithm::create(JS::Realm& realm)
{
return realm.heap().allocate<RsaHashedKeyAlgorithm>(realm, realm);