/* * Copyright (c) 2023, stelar7 * Copyright (c) 2024, Andrew Kaster * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::Crypto { // https://w3c.github.io/webcrypto/#key-algorithm-dictionary class KeyAlgorithm : public JS::Object { JS_OBJECT(KeyAlgorithm, Object); JS_DECLARE_ALLOCATOR(KeyAlgorithm); public: static JS::NonnullGCPtr create(JS::Realm&); virtual ~KeyAlgorithm() override = default; String const& name() const { return m_name; } void set_name(String name) { m_name = move(name); } JS::Realm& realm() const { return m_realm; } protected: KeyAlgorithm(JS::Realm&); virtual void initialize(JS::Realm&) override; private: JS_DECLARE_NATIVE_FUNCTION(name_getter); String m_name; JS::Realm& m_realm; }; // https://w3c.github.io/webcrypto/#RsaKeyAlgorithm-dictionary class RsaKeyAlgorithm : public KeyAlgorithm { JS_OBJECT(RsaKeyAlgorithm, KeyAlgorithm); JS_DECLARE_ALLOCATOR(RsaKeyAlgorithm); public: static JS::NonnullGCPtr create(JS::Realm&); virtual ~RsaKeyAlgorithm() override = default; u32 modulus_length() const { return m_modulus_length; } void set_modulus_length(u32 modulus_length) { m_modulus_length = modulus_length; } JS::NonnullGCPtr public_exponent() const { return m_public_exponent; } void set_public_exponent(JS::NonnullGCPtr public_exponent) { m_public_exponent = public_exponent; } WebIDL::ExceptionOr set_public_exponent(::Crypto::UnsignedBigInteger); protected: RsaKeyAlgorithm(JS::Realm&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; private: JS_DECLARE_NATIVE_FUNCTION(modulus_length_getter); JS_DECLARE_NATIVE_FUNCTION(public_exponent_getter); u32 m_modulus_length { 0 }; JS::NonnullGCPtr m_public_exponent; }; // https://w3c.github.io/webcrypto/#RsaHashedKeyAlgorithm-dictionary class RsaHashedKeyAlgorithm : public RsaKeyAlgorithm { JS_OBJECT(RsaHashedKeyAlgorithm, RsaKeyAlgorithm); JS_DECLARE_ALLOCATOR(RsaHashedKeyAlgorithm); public: static JS::NonnullGCPtr create(JS::Realm&); virtual ~RsaHashedKeyAlgorithm() override = default; HashAlgorithmIdentifier const& hash() const { return m_hash; } void set_hash(HashAlgorithmIdentifier hash) { m_hash = move(hash); } protected: RsaHashedKeyAlgorithm(JS::Realm&); virtual void initialize(JS::Realm&) override; private: JS_DECLARE_NATIVE_FUNCTION(hash_getter); HashAlgorithmIdentifier m_hash; }; }