123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- /*
- * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
- * Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
- * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
- #pragma once
- #include <AK/EnumBits.h>
- #include <AK/String.h>
- #include <LibCrypto/BigInt/UnsignedBigInteger.h>
- #include <LibGC/Ptr.h>
- #include <LibJS/Forward.h>
- #include <LibWeb/Bindings/SubtleCryptoPrototype.h>
- #include <LibWeb/Crypto/CryptoBindings.h>
- #include <LibWeb/Crypto/CryptoKey.h>
- #include <LibWeb/WebIDL/Buffers.h>
- #include <LibWeb/WebIDL/ExceptionOr.h>
- #include <LibWeb/WebIDL/Types.h>
- namespace Web::Crypto {
- using AlgorithmIdentifier = Variant<GC::Root<JS::Object>, String>;
- using NamedCurve = String;
- using KeyDataType = Variant<GC::Root<WebIDL::BufferSource>, Bindings::JsonWebKey>;
- struct HashAlgorithmIdentifier : public AlgorithmIdentifier {
- using AlgorithmIdentifier::AlgorithmIdentifier;
- JS::ThrowCompletionOr<String> name(JS::VM& vm) const
- {
- auto value = visit(
- [](String const& name) -> JS::ThrowCompletionOr<String> { return name; },
- [&](GC::Root<JS::Object> const& obj) -> JS::ThrowCompletionOr<String> {
- auto name_property = TRY(obj->get("name"));
- return name_property.to_string(vm);
- });
- return value;
- }
- };
- // https://w3c.github.io/webcrypto/#algorithm-overview
- struct AlgorithmParams {
- virtual ~AlgorithmParams();
- explicit AlgorithmParams(String name)
- : name(move(name))
- {
- }
- String name;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#aes-cbc
- struct AesCbcParams : public AlgorithmParams {
- virtual ~AesCbcParams() override;
- AesCbcParams(String name, ByteBuffer iv)
- : AlgorithmParams(move(name))
- , iv(move(iv))
- {
- }
- ByteBuffer iv;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-AesCtrParams
- struct AesCtrParams : public AlgorithmParams {
- virtual ~AesCtrParams() override;
- AesCtrParams(String name, ByteBuffer counter, u8 length)
- : AlgorithmParams(move(name))
- , counter(move(counter))
- , length(length)
- {
- }
- ByteBuffer counter;
- u8 length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-AesGcmParams
- struct AesGcmParams : public AlgorithmParams {
- virtual ~AesGcmParams() override;
- AesGcmParams(String name, ByteBuffer iv, Optional<ByteBuffer> additional_data, Optional<u8> tag_length)
- : AlgorithmParams(move(name))
- , iv(move(iv))
- , additional_data(move(additional_data))
- , tag_length(tag_length)
- {
- }
- ByteBuffer iv;
- Optional<ByteBuffer> additional_data;
- Optional<u8> tag_length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#hkdf-params
- struct HKDFParams : public AlgorithmParams {
- virtual ~HKDFParams() override;
- HKDFParams(String name, HashAlgorithmIdentifier hash, ByteBuffer salt, ByteBuffer info)
- : AlgorithmParams(move(name))
- , hash(move(hash))
- , salt(move(salt))
- , info(move(info))
- {
- }
- HashAlgorithmIdentifier hash;
- ByteBuffer salt;
- ByteBuffer info;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#pbkdf2-params
- struct PBKDF2Params : public AlgorithmParams {
- virtual ~PBKDF2Params() override;
- PBKDF2Params(String name, ByteBuffer salt, u32 iterations, HashAlgorithmIdentifier hash)
- : AlgorithmParams(move(name))
- , salt(move(salt))
- , iterations(iterations)
- , hash(move(hash))
- {
- }
- ByteBuffer salt;
- u32 iterations;
- HashAlgorithmIdentifier hash;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-RsaKeyGenParams
- struct RsaKeyGenParams : public AlgorithmParams {
- virtual ~RsaKeyGenParams() override;
- RsaKeyGenParams(String name, u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent)
- : AlgorithmParams(move(name))
- , modulus_length(modulus_length)
- , public_exponent(move(public_exponent))
- {
- }
- u32 modulus_length;
- // NOTE that the raw data is going to be in Big Endian u8[] format
- ::Crypto::UnsignedBigInteger public_exponent;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-RsaHashedKeyGenParams
- struct RsaHashedKeyGenParams : public RsaKeyGenParams {
- virtual ~RsaHashedKeyGenParams() override;
- RsaHashedKeyGenParams(String name, u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent, HashAlgorithmIdentifier hash)
- : RsaKeyGenParams(move(name), modulus_length, move(public_exponent))
- , hash(move(hash))
- {
- }
- HashAlgorithmIdentifier hash;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-RsaHashedImportParams
- struct RsaHashedImportParams : public AlgorithmParams {
- virtual ~RsaHashedImportParams() override;
- RsaHashedImportParams(String name, HashAlgorithmIdentifier hash)
- : AlgorithmParams(move(name))
- , hash(move(hash))
- {
- }
- HashAlgorithmIdentifier hash;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-RsaOaepParams
- struct RsaOaepParams : public AlgorithmParams {
- virtual ~RsaOaepParams() override;
- RsaOaepParams(String name, ByteBuffer label)
- : AlgorithmParams(move(name))
- , label(move(label))
- {
- }
- ByteBuffer label;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-EcdsaParams
- struct EcdsaParams : public AlgorithmParams {
- virtual ~EcdsaParams() override;
- EcdsaParams(String name, HashAlgorithmIdentifier hash)
- : AlgorithmParams(move(name))
- , hash(move(hash))
- {
- }
- HashAlgorithmIdentifier hash;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-EcKeyGenParams
- struct EcKeyGenParams : public AlgorithmParams {
- virtual ~EcKeyGenParams() override;
- EcKeyGenParams(String name, NamedCurve named_curve)
- : AlgorithmParams(move(name))
- , named_curve(move(named_curve))
- {
- }
- NamedCurve named_curve;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-AesKeyGenParams
- struct AesKeyGenParams : public AlgorithmParams {
- virtual ~AesKeyGenParams() override;
- AesKeyGenParams(String name, u16 length)
- : AlgorithmParams(move(name))
- , length(length)
- {
- }
- u16 length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#dfn-AesDerivedKeyParams
- struct AesDerivedKeyParams : public AlgorithmParams {
- virtual ~AesDerivedKeyParams() override;
- AesDerivedKeyParams(String name, u16 length)
- : AlgorithmParams(move(name))
- , length(length)
- {
- }
- u16 length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#hmac-importparams
- struct HmacImportParams : public AlgorithmParams {
- virtual ~HmacImportParams() override;
- HmacImportParams(String name, HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length)
- : AlgorithmParams(move(name))
- , hash(move(hash))
- , length(length)
- {
- }
- HashAlgorithmIdentifier hash;
- Optional<WebIDL::UnsignedLong> length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- // https://w3c.github.io/webcrypto/#hmac-keygen-params
- struct HmacKeyGenParams : public AlgorithmParams {
- virtual ~HmacKeyGenParams() override;
- HmacKeyGenParams(String name, HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length)
- : AlgorithmParams(move(name))
- , hash(move(hash))
- , length(length)
- {
- }
- HashAlgorithmIdentifier hash;
- Optional<WebIDL::UnsignedLong> length;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- class AlgorithmMethods {
- public:
- virtual ~AlgorithmMethods();
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> encrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "encrypt is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> decrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "decrypt is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> sign(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "sign is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<JS::Value> verify(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&, ByteBuffer const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "verify is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> digest(AlgorithmParams const&, ByteBuffer const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "digest is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>)
- {
- return WebIDL::NotSupportedError::create(m_realm, "deriveBits is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "importKey is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "generateKey is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>)
- {
- return WebIDL::NotSupportedError::create(m_realm, "exportKey is not supported"_string);
- }
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&)
- {
- return WebIDL::NotSupportedError::create(m_realm, "getKeyLength is not supported"_string);
- }
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AlgorithmMethods(realm)); }
- protected:
- explicit AlgorithmMethods(JS::Realm& realm)
- : m_realm(realm)
- {
- }
- GC::Ref<JS::Realm> m_realm;
- };
- class RSAOAEP : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> encrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> decrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new RSAOAEP(realm)); }
- private:
- explicit RSAOAEP(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class AesCbc : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> encrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> decrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AesCbc(realm)); }
- private:
- explicit AesCbc(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class AesCtr : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> encrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> decrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AesCtr(realm)); }
- private:
- explicit AesCtr(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class AesGcm : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> encrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> decrypt(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AesGcm(realm)); }
- private:
- explicit AesGcm(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class HKDF : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>) override;
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new HKDF(realm)); }
- private:
- explicit HKDF(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class PBKDF2 : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>) override;
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new PBKDF2(realm)); }
- private:
- explicit PBKDF2(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class SHA : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> digest(AlgorithmParams const&, ByteBuffer const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new SHA(realm)); }
- private:
- explicit SHA(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class ECDSA : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> sign(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<JS::Value> verify(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new ECDSA(realm)); }
- private:
- explicit ECDSA(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class ECDH : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- // TODO: virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>) override;
- // TODO: virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- // TODO: virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new ECDH(realm)); }
- private:
- explicit ECDH(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class ED25519 : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> sign(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<JS::Value> verify(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new ED25519(realm)); }
- private:
- explicit ED25519(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class X25519 : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, GC::Ref<CryptoKey>, Optional<u32>) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new X25519(realm)); }
- private:
- explicit X25519(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- class HMAC : public AlgorithmMethods {
- public:
- virtual WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> sign(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<JS::Value> verify(AlgorithmParams const&, GC::Ref<CryptoKey>, ByteBuffer const&, ByteBuffer const&) override;
- virtual WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
- virtual WebIDL::ExceptionOr<GC::Ref<JS::Object>> export_key(Bindings::KeyFormat, GC::Ref<CryptoKey>) override;
- virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
- static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new HMAC(realm)); }
- private:
- explicit HMAC(JS::Realm& realm)
- : AlgorithmMethods(realm)
- {
- }
- };
- struct EcdhKeyDerivePrams : public AlgorithmParams {
- virtual ~EcdhKeyDerivePrams() override;
- EcdhKeyDerivePrams(String name, CryptoKey& public_key)
- : AlgorithmParams(move(name))
- , public_key(public_key)
- {
- }
- GC::Ref<CryptoKey> public_key;
- static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
- };
- ErrorOr<String> base64_url_uint_encode(::Crypto::UnsignedBigInteger);
- WebIDL::ExceptionOr<ByteBuffer> base64_url_bytes_decode(JS::Realm&, String const& base64_url_string);
- WebIDL::ExceptionOr<::Crypto::UnsignedBigInteger> base64_url_uint_decode(JS::Realm&, String const& base64_url_string);
- }
|