LibWeb: Implement AES-CTR.getKeyLength

This commit is contained in:
stelar7 2024-10-30 22:53:47 +01:00 committed by Andreas Kling
parent 0864436383
commit 030cbef532
Notes: github-actions[bot] 2024-10-31 07:16:17 +00:00
3 changed files with 14 additions and 0 deletions

View file

@ -1517,6 +1517,18 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> AesCtr::import_key(AlgorithmPar
return key;
}
WebIDL::ExceptionOr<JS::Value> AesCtr::get_key_length(AlgorithmParams const& params)
{
// 1. If the length member of normalizedDerivedKeyAlgorithm is not 128, 192 or 256, then throw a OperationError.
auto const& normalized_algorithm = static_cast<AesDerivedKeyParams const&>(params);
auto length = normalized_algorithm.length;
if (length != 128 && length != 192 && length != 256)
return WebIDL::OperationError::create(m_realm, "Invalid key length"_string);
// 2. Return the length member of normalizedDerivedKeyAlgorithm.
return JS::Value(length);
}
// https://w3c.github.io/webcrypto/#hkdf-operations
WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> HKDF::import_key(AlgorithmParams const&, Bindings::KeyFormat format, CryptoKey::InternalKeyData key_data, bool extractable, Vector<Bindings::KeyUsage> const& key_usages)
{

View file

@ -330,6 +330,7 @@ private:
class AesCtr : public AlgorithmMethods {
public:
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AesCtr(realm)); }

View file

@ -778,6 +778,7 @@ SupportedAlgorithmsMap supported_algorithms()
// https://w3c.github.io/webcrypto/#aes-ctr-registration
define_an_algorithm<AesCtr>("importKey"_string, "AES-CTR"_string);
define_an_algorithm<AesCtr, AesDerivedKeyParams>("get key length"_string, "AES-CTR"_string);
// https://w3c.github.io/webcrypto/#hkdf
define_an_algorithm<HKDF>("importKey"_string, "HKDF"_string);