2021-12-13 20:48:27 +00:00
|
|
|
/*
|
2022-08-22 18:31:08 +01:00
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
2023-12-15 22:03:04 +01:00
|
|
|
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
2021-12-13 20:48:27 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-14 00:38:14 +01:00
|
|
|
#include <AK/String.h>
|
2023-12-15 22:03:04 +01:00
|
|
|
#include <AK/Vector.h>
|
2021-12-13 22:09:55 +00:00
|
|
|
#include <LibJS/Forward.h>
|
2022-09-03 19:59:53 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2023-12-15 22:03:04 +01:00
|
|
|
#include <LibWeb/Bindings/SubtleCryptoPrototype.h>
|
2024-03-06 16:53:50 -07:00
|
|
|
#include <LibWeb/Crypto/CryptoAlgorithms.h>
|
2023-12-15 22:03:04 +01:00
|
|
|
#include <LibWeb/Crypto/CryptoKey.h>
|
2021-12-13 20:48:27 +00:00
|
|
|
|
|
|
|
namespace Web::Crypto {
|
|
|
|
|
2022-09-03 19:59:53 +02:00
|
|
|
class SubtleCrypto final : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(SubtleCrypto);
|
2022-09-03 19:59:53 +02:00
|
|
|
|
2021-12-13 20:48:27 +00:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<SubtleCrypto> create(JS::Realm&);
|
2021-12-13 20:48:27 +00:00
|
|
|
|
2022-09-03 19:59:53 +02:00
|
|
|
virtual ~SubtleCrypto() override;
|
2021-12-13 20:48:27 +00:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<WebIDL::Promise> encrypt(AlgorithmIdentifier const& algorithm, GC::Ref<CryptoKey> key, GC::Root<WebIDL::BufferSource> const& data_parameter);
|
|
|
|
GC::Ref<WebIDL::Promise> decrypt(AlgorithmIdentifier const& algorithm, GC::Ref<CryptoKey> key, GC::Root<WebIDL::BufferSource> const& data_parameter);
|
2025-01-31 11:18:03 +01:00
|
|
|
GC::Ref<WebIDL::Promise> sign(AlgorithmIdentifier const& algorithm, GC::Ref<CryptoKey> key, GC::Root<WebIDL::BufferSource> const& data_parameter);
|
|
|
|
GC::Ref<WebIDL::Promise> verify(AlgorithmIdentifier const& algorithm, GC::Ref<CryptoKey> key, GC::Root<WebIDL::BufferSource> const& signature, GC::Root<WebIDL::BufferSource> const& data_parameter);
|
2024-03-14 22:39:48 -06:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<WebIDL::Promise> digest(AlgorithmIdentifier const& algorithm, GC::Root<WebIDL::BufferSource> const& data);
|
2024-03-06 16:53:50 -07:00
|
|
|
|
2025-01-31 11:18:03 +01:00
|
|
|
GC::Ref<WebIDL::Promise> generate_key(AlgorithmIdentifier algorithm, bool extractable, Vector<Bindings::KeyUsage> key_usages);
|
|
|
|
GC::Ref<WebIDL::Promise> derive_bits(AlgorithmIdentifier algorithm, GC::Ref<CryptoKey> base_key, Optional<u32> length_optional);
|
|
|
|
GC::Ref<WebIDL::Promise> derive_key(AlgorithmIdentifier algorithm, GC::Ref<CryptoKey> base_key, AlgorithmIdentifier derived_key_type, bool extractable, Vector<Bindings::KeyUsage> key_usages);
|
2024-03-06 19:15:03 -07:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> import_key(Bindings::KeyFormat format, KeyDataType key_data, AlgorithmIdentifier algorithm, bool extractable, Vector<Bindings::KeyUsage> key_usages);
|
2025-01-31 11:18:03 +01:00
|
|
|
GC::Ref<WebIDL::Promise> export_key(Bindings::KeyFormat format, GC::Ref<CryptoKey> key);
|
2021-12-13 22:09:55 +00:00
|
|
|
|
2025-01-31 11:18:03 +01:00
|
|
|
GC::Ref<WebIDL::Promise> wrap_key(Bindings::KeyFormat format, GC::Ref<CryptoKey> key, GC::Ref<CryptoKey> wrapping_key, AlgorithmIdentifier wrap_algorithm);
|
|
|
|
GC::Ref<WebIDL::Promise> unwrap_key(Bindings::KeyFormat format, KeyDataType wrapped_key, GC::Ref<CryptoKey> unwrapping_key, AlgorithmIdentifier unwrap_algorithm, AlgorithmIdentifier unwrapped_key_algorithm, bool extractable, Vector<Bindings::KeyUsage> key_usages);
|
2024-12-14 12:23:52 +01:00
|
|
|
|
2021-12-13 20:48:27 +00:00
|
|
|
private:
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
explicit SubtleCrypto(JS::Realm&);
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2024-03-14 21:52:17 -06:00
|
|
|
};
|
2023-12-14 00:38:14 +01:00
|
|
|
|
2024-03-14 21:52:17 -06:00
|
|
|
struct NormalizedAlgorithmAndParameter {
|
|
|
|
NonnullOwnPtr<AlgorithmMethods> methods;
|
|
|
|
NonnullOwnPtr<AlgorithmParams> parameter;
|
2021-12-13 20:48:27 +00:00
|
|
|
};
|
2024-03-14 21:52:17 -06:00
|
|
|
WebIDL::ExceptionOr<NormalizedAlgorithmAndParameter> normalize_an_algorithm(JS::Realm&, AlgorithmIdentifier const& algorithm, String operation);
|
2021-12-13 20:48:27 +00:00
|
|
|
|
|
|
|
}
|