diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 0e59ce8c04d..5fcb21c8433 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -274,6 +274,32 @@ static WebIDL::ExceptionOr generate_random_key(JS::VM& vm, u16 const return key_buffer; } +JS::ThrowCompletionOr> EncapsulatedKey::to_object(JS::Realm& realm) +{ + auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); + + if (shared_key.has_value()) + TRY(object->create_data_property("shared_key"_utf16_fly_string, shared_key.value())); + + if (ciphertext.has_value()) + TRY(object->create_data_property("ciphertext"_utf16_fly_string, JS::ArrayBuffer::create(realm, ciphertext.value()))); + + return object; +} + +JS::ThrowCompletionOr> EncapsulatedBits::to_object(JS::Realm& realm) +{ + auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); + + if (shared_key.has_value()) + TRY(object->create_data_property("shared_key"_utf16_fly_string, JS::ArrayBuffer::create(realm, shared_key.value()))); + + if (ciphertext.has_value()) + TRY(object->create_data_property("ciphertext"_utf16_fly_string, JS::ArrayBuffer::create(realm, ciphertext.value()))); + + return object; +} + AlgorithmParams::~AlgorithmParams() = default; JS::ThrowCompletionOr> AlgorithmParams::from_value(JS::VM&, JS::Value) diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.h b/Libraries/LibWeb/Crypto/CryptoAlgorithms.h index cbdd8fd992b..7a1c4dda8fc 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.h +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.h @@ -26,6 +26,22 @@ using AlgorithmIdentifier = Variant, String>; using NamedCurve = String; using KeyDataType = Variant, Bindings::JsonWebKey>; +// https://wicg.github.io/webcrypto-modern-algos/#encapsulation +struct EncapsulatedKey { + Optional> shared_key; + Optional ciphertext; + + JS::ThrowCompletionOr> to_object(JS::Realm&); +}; + +// https://wicg.github.io/webcrypto-modern-algos/#encapsulation +struct EncapsulatedBits { + Optional shared_key; + Optional ciphertext; + + JS::ThrowCompletionOr> to_object(JS::Realm&); +}; + struct HashAlgorithmIdentifier : public AlgorithmIdentifier { using AlgorithmIdentifier::AlgorithmIdentifier; diff --git a/Libraries/LibWeb/Crypto/SubtleCrypto.idl b/Libraries/LibWeb/Crypto/SubtleCrypto.idl index 550c4b2acab..4950d700209 100644 --- a/Libraries/LibWeb/Crypto/SubtleCrypto.idl +++ b/Libraries/LibWeb/Crypto/SubtleCrypto.idl @@ -42,6 +42,18 @@ dictionary JsonWebKey { DOMString k; }; +// https://wicg.github.io/webcrypto-modern-algos/#encapsulation +dictionary EncapsulatedKey { + CryptoKey sharedKey; + ArrayBuffer ciphertext; +}; + +// https://wicg.github.io/webcrypto-modern-algos/#encapsulation +dictionary EncapsulatedBits { + ArrayBuffer sharedKey; + ArrayBuffer ciphertext; +}; + // https://w3c.github.io/webcrypto/#subtlecrypto-interface [SecureContext,Exposed=(Window,Worker)] interface SubtleCrypto {