LibWeb: Implement AES-GCM.getKeyLength
This commit is contained in:
parent
a733e2a31c
commit
80d37a6def
Notes:
github-actions[bot]
2024-10-31 22:35:20 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/80d37a6def9 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2085
3 changed files with 28 additions and 0 deletions
|
@ -1757,6 +1757,18 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> AesCtr::decrypt(Algorithm
|
|||
return JS::ArrayBuffer::create(m_realm, plaintext);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::Value> AesGcm::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)
|
||||
{
|
||||
|
|
|
@ -362,6 +362,19 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class AesGcm : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
|
||||
|
||||
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new AesGcm(realm)); }
|
||||
|
||||
private:
|
||||
explicit AesGcm(JS::Realm& realm)
|
||||
: AlgorithmMethods(realm)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class HKDF : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
|
||||
|
|
|
@ -784,6 +784,9 @@ SupportedAlgorithmsMap supported_algorithms()
|
|||
define_an_algorithm<AesCtr, AesDerivedKeyParams>("get key length"_string, "AES-CTR"_string);
|
||||
define_an_algorithm<AesCtr, AesKeyGenParams>("generateKey"_string, "AES-CTR"_string);
|
||||
|
||||
// https://w3c.github.io/webcrypto/#aes-gcm-registration
|
||||
define_an_algorithm<AesGcm, AesDerivedKeyParams>("get key length"_string, "AES-GCM"_string);
|
||||
|
||||
// https://w3c.github.io/webcrypto/#hkdf
|
||||
define_an_algorithm<HKDF>("importKey"_string, "HKDF"_string);
|
||||
define_an_algorithm<HKDF, HKDFParams>("deriveBits"_string, "HKDF"_string);
|
||||
|
|
Loading…
Add table
Reference in a new issue