/* * 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 #include namespace Web::Crypto { class SubtleCrypto final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject); JS_DECLARE_ALLOCATOR(SubtleCrypto); public: [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&); virtual ~SubtleCrypto() override; JS::NonnullGCPtr encrypt(AlgorithmIdentifier const& algorithm, JS::NonnullGCPtr key, JS::Handle const& data_parameter); JS::NonnullGCPtr decrypt(AlgorithmIdentifier const& algorithm, JS::NonnullGCPtr key, JS::Handle const& data_parameter); JS::ThrowCompletionOr> sign(AlgorithmIdentifier const& algorithm, JS::NonnullGCPtr key, JS::Handle const& data_parameter); JS::ThrowCompletionOr> verify(AlgorithmIdentifier const& algorithm, JS::NonnullGCPtr key, JS::Handle const& signature, JS::Handle const& data_parameter); JS::NonnullGCPtr digest(AlgorithmIdentifier const& algorithm, JS::Handle const& data); JS::ThrowCompletionOr> generate_key(AlgorithmIdentifier algorithm, bool extractable, Vector key_usages); JS::ThrowCompletionOr> derive_bits(AlgorithmIdentifier algorithm, JS::NonnullGCPtr base_key, u32 length); JS::ThrowCompletionOr> derive_key(AlgorithmIdentifier algorithm, JS::NonnullGCPtr 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, JS::NonnullGCPtr key); 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); }