1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

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.
This commit is contained in:
Andrew Kaster 2024-03-06 16:53:50 -07:00 committed by Andrew Kaster
parent 644e764620
commit 2d59d6c98c
9 changed files with 294 additions and 136 deletions

View file

@ -11,6 +11,7 @@
#include <LibWeb/Bindings/CryptoKeyPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Crypto/CryptoBindings.h>
namespace Web::Crypto {
@ -19,7 +20,9 @@ class CryptoKey final : public Bindings::PlatformObject {
JS_DECLARE_ALLOCATOR(CryptoKey);
public:
[[nodiscard]] static JS::NonnullGCPtr<CryptoKey> create(JS::Realm&);
using InternalKeyData = Variant<ByteBuffer, Bindings::JsonWebKey>;
[[nodiscard]] static JS::NonnullGCPtr<CryptoKey> create(JS::Realm&, InternalKeyData);
virtual ~CryptoKey() override;
@ -34,7 +37,7 @@ public:
void set_usages(JS::NonnullGCPtr<Object> usages) { m_usages = move(usages); }
private:
explicit CryptoKey(JS::Realm&);
CryptoKey(JS::Realm&, InternalKeyData);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
@ -42,6 +45,8 @@ private:
bool m_extractable { false };
JS::NonnullGCPtr<Object> m_algorithm;
JS::NonnullGCPtr<Object> m_usages;
InternalKeyData m_key_data;
};
}