1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00
serenity/Userland/Libraries/LibWeb/Crypto/CryptoKey.h
Andrew Kaster 2d59d6c98c LibWeb: Refactor SubtleCrypto to allow adding more algorithms easier
This patch throws away some of the spec suggestions for how to implement
the normalize_algorithm AO and uses a new pattern that we can actually
extend in our C++.

Also update CryptoKey to store the key data.
2024-03-13 15:31:00 -06:00

52 lines
1.6 KiB
C++

/*
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Bindings/CryptoKeyPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Crypto/CryptoBindings.h>
namespace Web::Crypto {
class CryptoKey final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(CryptoKey, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(CryptoKey);
public:
using InternalKeyData = Variant<ByteBuffer, Bindings::JsonWebKey>;
[[nodiscard]] static JS::NonnullGCPtr<CryptoKey> create(JS::Realm&, InternalKeyData);
virtual ~CryptoKey() override;
bool extractable() const { return m_extractable; }
Bindings::KeyType type() const { return m_type; }
Object const* algorithm() const { return m_algorithm.ptr(); }
Object const* usages() const { return m_usages.ptr(); }
void set_extractable(bool extractable) { m_extractable = extractable; }
void set_type(Bindings::KeyType type) { m_type = type; }
void set_algorithm(JS::NonnullGCPtr<Object> algorithm) { m_algorithm = move(algorithm); }
void set_usages(JS::NonnullGCPtr<Object> usages) { m_usages = move(usages); }
private:
CryptoKey(JS::Realm&, InternalKeyData);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
Bindings::KeyType m_type;
bool m_extractable { false };
JS::NonnullGCPtr<Object> m_algorithm;
JS::NonnullGCPtr<Object> m_usages;
InternalKeyData m_key_data;
};
}