/* * Copyright (c) 2021-2022, Linus Groh * Copyright (c) 2023, stelar7 * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::Crypto { class SubtleCrypto final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(SubtleCrypto); public: [[nodiscard]] static GC::Ref create(JS::Realm&); virtual ~SubtleCrypto() override; GC::Ref encrypt(AlgorithmIdentifier const& algorithm, GC::Ref key, GC::Root const& data_parameter); GC::Ref decrypt(AlgorithmIdentifier const& algorithm, GC::Ref key, GC::Root const& data_parameter); JS::ThrowCompletionOr> sign(AlgorithmIdentifier const& algorithm, GC::Ref key, GC::Root const& data_parameter); JS::ThrowCompletionOr> verify(AlgorithmIdentifier const& algorithm, GC::Ref key, GC::Root const& signature, GC::Root const& data_parameter); GC::Ref digest(AlgorithmIdentifier const& algorithm, GC::Root const& data); JS::ThrowCompletionOr> generate_key(AlgorithmIdentifier algorithm, bool extractable, Vector key_usages); JS::ThrowCompletionOr> derive_bits(AlgorithmIdentifier algorithm, GC::Ref base_key, u32 length); JS::ThrowCompletionOr> derive_key(AlgorithmIdentifier algorithm, GC::Ref base_key, AlgorithmIdentifier derived_key_type, bool extractable, Vector key_usages); JS::ThrowCompletionOr> import_key(Bindings::KeyFormat format, KeyDataType key_data, AlgorithmIdentifier algorithm, bool extractable, Vector key_usages); JS::ThrowCompletionOr> export_key(Bindings::KeyFormat format, GC::Ref key); JS::ThrowCompletionOr> wrap_key(Bindings::KeyFormat format, GC::Ref key, GC::Ref wrapping_key, AlgorithmIdentifier wrap_algorithm); JS::ThrowCompletionOr> unwrap_key(Bindings::KeyFormat format, KeyDataType wrapped_key, GC::Ref unwrapping_key, AlgorithmIdentifier unwrap_algorithm, AlgorithmIdentifier unwrapped_key_algorithm, bool extractable, Vector key_usages); private: explicit SubtleCrypto(JS::Realm&); virtual void initialize(JS::Realm&) override; }; struct NormalizedAlgorithmAndParameter { NonnullOwnPtr methods; NonnullOwnPtr parameter; }; WebIDL::ExceptionOr normalize_an_algorithm(JS::Realm&, AlgorithmIdentifier const& algorithm, String operation); }