/* * 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); using SupportedAlgorithmsMap = HashMap>; using KeyDataType = Variant, Bindings::JsonWebKey>; using AlgorithmIdentifier = Variant, String>; public: [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&); virtual ~SubtleCrypto() override; JS::NonnullGCPtr digest(AlgorithmIdentifier const& algorithm, JS::Handle const& data); JS::ThrowCompletionOr> import_key(Bindings::KeyFormat format, KeyDataType keyData, AlgorithmIdentifier algorithm, bool extractable, Vector keyUsages); private: explicit SubtleCrypto(JS::Realm&); virtual void initialize(JS::Realm&) override; JS::ThrowCompletionOr normalize_an_algorithm(AlgorithmIdentifier const& algorithm, String operation); WebIDL::ExceptionOr> pbkdf2_import_key(Variant key_data, AlgorithmIdentifier algorithm, Bindings::KeyFormat format, bool extractable, Vector usages); static SubtleCrypto::SupportedAlgorithmsMap& supported_algorithms_internal(); static SubtleCrypto::SupportedAlgorithmsMap supported_algorithms(); static void define_an_algorithm(String op, String algorithm, String type); }; }