1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 01:51:03 +09:00

LibWeb: Match algorithm names case-insensitive

I dug through the code and the WebCryptoAPI spec to figure out the
reason for `... mixed case parameters` WPT tests and figured out that
our implementation was slightly wrong.

By being closer to the spec we can now pass those tests and also remove
a bunch of duplicated code.

Context: https://github.com/LadybirdBrowser/ladybird/pull/2598#discussion_r1859263798
This commit is contained in:
devgianlu 2024-11-27 21:17:07 +01:00 committed by Andreas Kling
parent 6ebc812035
commit 46e724729c
Notes: github-actions[bot] 2024-11-27 23:22:41 +00:00
6 changed files with 74 additions and 139 deletions

View file

@ -314,14 +314,9 @@ static WebIDL::ExceptionOr<ByteBuffer> generate_random_key(JS::VM& vm, u16 const
AlgorithmParams::~AlgorithmParams() = default; AlgorithmParams::~AlgorithmParams() = default;
JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AlgorithmParams::from_value(JS::VM& vm, JS::Value value) JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AlgorithmParams::from_value(JS::VM&, JS::Value)
{ {
auto& object = value.as_object(); return adopt_own(*new AlgorithmParams {});
auto name = TRY(object.get("name"));
auto name_string = TRY(name.to_string(vm));
return adopt_own(*new AlgorithmParams { name_string });
} }
AesCbcParams::~AesCbcParams() = default; AesCbcParams::~AesCbcParams() = default;
@ -330,15 +325,12 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesCbcParams::from_value(J
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto iv_value = TRY(object.get("iv")); auto iv_value = TRY(object.get("iv"));
if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object()))) if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object())))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource");
auto iv = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(iv_value.as_object())); auto iv = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(iv_value.as_object()));
return adopt_own<AlgorithmParams>(*new AesCbcParams { name, iv }); return adopt_own<AlgorithmParams>(*new AesCbcParams { iv });
} }
AesCtrParams::~AesCtrParams() = default; AesCtrParams::~AesCtrParams() = default;
@ -347,9 +339,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesCtrParams::from_value(J
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto iv_value = TRY(object.get("counter")); auto iv_value = TRY(object.get("counter"));
if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object()))) if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object())))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource");
@ -358,7 +347,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesCtrParams::from_value(J
auto length_value = TRY(object.get("length")); auto length_value = TRY(object.get("length"));
auto length = TRY(length_value.to_u8(vm)); auto length = TRY(length_value.to_u8(vm));
return adopt_own<AlgorithmParams>(*new AesCtrParams { name, iv, length }); return adopt_own<AlgorithmParams>(*new AesCtrParams { iv, length });
} }
AesGcmParams::~AesGcmParams() = default; AesGcmParams::~AesGcmParams() = default;
@ -367,9 +356,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesGcmParams::from_value(J
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto iv_value = TRY(object.get("iv")); auto iv_value = TRY(object.get("iv"));
if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object()))) if (!iv_value.is_object() || !(is<JS::TypedArrayBase>(iv_value.as_object()) || is<JS::ArrayBuffer>(iv_value.as_object()) || is<JS::DataView>(iv_value.as_object())))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource");
@ -389,7 +375,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesGcmParams::from_value(J
maybe_tag_length = TRY(tag_length_value.to_u8(vm)); maybe_tag_length = TRY(tag_length_value.to_u8(vm));
} }
return adopt_own<AlgorithmParams>(*new AesGcmParams { name, iv, maybe_additional_data, maybe_tag_length }); return adopt_own<AlgorithmParams>(*new AesGcmParams { iv, maybe_additional_data, maybe_tag_length });
} }
HKDFParams::~HKDFParams() = default; HKDFParams::~HKDFParams() = default;
@ -398,9 +384,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HKDFParams::from_value(JS:
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
@ -414,7 +397,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HKDFParams::from_value(JS:
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "BufferSource");
auto info = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(info_value.as_object())); auto info = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(info_value.as_object()));
return adopt_own<AlgorithmParams>(*new HKDFParams { name, hash, salt, info }); return adopt_own<AlgorithmParams>(*new HKDFParams { hash, salt, info });
} }
PBKDF2Params::~PBKDF2Params() = default; PBKDF2Params::~PBKDF2Params() = default;
@ -423,9 +406,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> PBKDF2Params::from_value(J
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto salt_value = TRY(object.get("salt")); auto salt_value = TRY(object.get("salt"));
if (!salt_value.is_object() || !(is<JS::TypedArrayBase>(salt_value.as_object()) || is<JS::ArrayBuffer>(salt_value.as_object()) || is<JS::DataView>(salt_value.as_object()))) if (!salt_value.is_object() || !(is<JS::TypedArrayBase>(salt_value.as_object()) || is<JS::ArrayBuffer>(salt_value.as_object()) || is<JS::DataView>(salt_value.as_object())))
@ -439,7 +419,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> PBKDF2Params::from_value(J
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
return adopt_own<AlgorithmParams>(*new PBKDF2Params { name, salt, iterations, hash }); return adopt_own<AlgorithmParams>(*new PBKDF2Params { salt, iterations, hash });
} }
RsaKeyGenParams::~RsaKeyGenParams() = default; RsaKeyGenParams::~RsaKeyGenParams() = default;
@ -448,9 +428,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaKeyGenParams::from_valu
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto modulus_length_value = TRY(object.get("modulusLength")); auto modulus_length_value = TRY(object.get("modulusLength"));
auto modulus_length = TRY(modulus_length_value.to_u32(vm)); auto modulus_length = TRY(modulus_length_value.to_u32(vm));
@ -462,7 +439,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaKeyGenParams::from_valu
public_exponent = static_cast<JS::Uint8Array&>(public_exponent_value.as_object()); public_exponent = static_cast<JS::Uint8Array&>(public_exponent_value.as_object());
return adopt_own<AlgorithmParams>(*new RsaKeyGenParams { name, modulus_length, big_integer_from_api_big_integer(public_exponent) }); return adopt_own<AlgorithmParams>(*new RsaKeyGenParams { modulus_length, big_integer_from_api_big_integer(public_exponent) });
} }
RsaHashedKeyGenParams::~RsaHashedKeyGenParams() = default; RsaHashedKeyGenParams::~RsaHashedKeyGenParams() = default;
@ -471,9 +448,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaHashedKeyGenParams::fro
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto modulus_length_value = TRY(object.get("modulusLength")); auto modulus_length_value = TRY(object.get("modulusLength"));
auto modulus_length = TRY(modulus_length_value.to_u32(vm)); auto modulus_length = TRY(modulus_length_value.to_u32(vm));
@ -488,7 +462,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaHashedKeyGenParams::fro
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
return adopt_own<AlgorithmParams>(*new RsaHashedKeyGenParams { name, modulus_length, big_integer_from_api_big_integer(public_exponent), hash }); return adopt_own<AlgorithmParams>(*new RsaHashedKeyGenParams { modulus_length, big_integer_from_api_big_integer(public_exponent), hash });
} }
RsaHashedImportParams::~RsaHashedImportParams() = default; RsaHashedImportParams::~RsaHashedImportParams() = default;
@ -497,13 +471,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaHashedImportParams::fro
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
return adopt_own<AlgorithmParams>(*new RsaHashedImportParams { name, hash }); return adopt_own<AlgorithmParams>(*new RsaHashedImportParams { hash });
} }
RsaOaepParams::~RsaOaepParams() = default; RsaOaepParams::~RsaOaepParams() = default;
@ -512,9 +483,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaOaepParams::from_value(
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto label_value = TRY(object.get("label")); auto label_value = TRY(object.get("label"));
ByteBuffer label; ByteBuffer label;
@ -525,7 +493,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> RsaOaepParams::from_value(
label = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(label_value.as_object())); label = TRY_OR_THROW_OOM(vm, WebIDL::get_buffer_source_copy(label_value.as_object()));
} }
return adopt_own<AlgorithmParams>(*new RsaOaepParams { name, move(label) }); return adopt_own<AlgorithmParams>(*new RsaOaepParams { move(label) });
} }
EcdsaParams::~EcdsaParams() = default; EcdsaParams::~EcdsaParams() = default;
@ -534,13 +502,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> EcdsaParams::from_value(JS
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
return adopt_own<AlgorithmParams>(*new EcdsaParams { name, hash }); return adopt_own<AlgorithmParams>(*new EcdsaParams { hash });
} }
EcKeyGenParams::~EcKeyGenParams() = default; EcKeyGenParams::~EcKeyGenParams() = default;
@ -549,13 +514,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> EcKeyGenParams::from_value
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto curve_value = TRY(object.get("namedCurve")); auto curve_value = TRY(object.get("namedCurve"));
auto curve = TRY(curve_value.to_string(vm)); auto curve = TRY(curve_value.to_string(vm));
return adopt_own<AlgorithmParams>(*new EcKeyGenParams { name, curve }); return adopt_own<AlgorithmParams>(*new EcKeyGenParams { curve });
} }
AesKeyGenParams::~AesKeyGenParams() = default; AesKeyGenParams::~AesKeyGenParams() = default;
@ -564,13 +526,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesKeyGenParams::from_valu
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto length_value = TRY(object.get("length")); auto length_value = TRY(object.get("length"));
auto length = TRY(length_value.to_u16(vm)); auto length = TRY(length_value.to_u16(vm));
return adopt_own<AlgorithmParams>(*new AesKeyGenParams { name, length }); return adopt_own<AlgorithmParams>(*new AesKeyGenParams { length });
} }
AesDerivedKeyParams::~AesDerivedKeyParams() = default; AesDerivedKeyParams::~AesDerivedKeyParams() = default;
@ -579,13 +538,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> AesDerivedKeyParams::from_
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto length_value = TRY(object.get("length")); auto length_value = TRY(object.get("length"));
auto length = TRY(length_value.to_u16(vm)); auto length = TRY(length_value.to_u16(vm));
return adopt_own<AlgorithmParams>(*new AesDerivedKeyParams { name, length }); return adopt_own<AlgorithmParams>(*new AesDerivedKeyParams { length });
} }
EcdhKeyDeriveParams::~EcdhKeyDeriveParams() = default; EcdhKeyDeriveParams::~EcdhKeyDeriveParams() = default;
@ -594,9 +550,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> EcdhKeyDeriveParams::from_
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto key_value = TRY(object.get("public")); auto key_value = TRY(object.get("public"));
auto key_object = TRY(key_value.to_object(vm)); auto key_object = TRY(key_value.to_object(vm));
@ -606,7 +559,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> EcdhKeyDeriveParams::from_
auto& key = verify_cast<CryptoKey>(*key_object); auto& key = verify_cast<CryptoKey>(*key_object);
return adopt_own<AlgorithmParams>(*new EcdhKeyDeriveParams { name, key }); return adopt_own<AlgorithmParams>(*new EcdhKeyDeriveParams { key });
} }
EcKeyImportParams::~EcKeyImportParams() = default; EcKeyImportParams::~EcKeyImportParams() = default;
@ -615,13 +568,10 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> EcKeyImportParams::from_va
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto named_curve_value = TRY(object.get("namedCurve")); auto named_curve_value = TRY(object.get("namedCurve"));
auto named_curve = TRY(named_curve_value.to_string(vm)); auto named_curve = TRY(named_curve_value.to_string(vm));
return adopt_own<AlgorithmParams>(*new EcKeyImportParams { name, named_curve }); return adopt_own<AlgorithmParams>(*new EcKeyImportParams { named_curve });
} }
HmacImportParams::~HmacImportParams() = default; HmacImportParams::~HmacImportParams() = default;
@ -630,9 +580,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HmacImportParams::from_val
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
@ -642,7 +589,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HmacImportParams::from_val
maybe_length = TRY(length_value.to_u32(vm)); maybe_length = TRY(length_value.to_u32(vm));
} }
return adopt_own<AlgorithmParams>(*new HmacImportParams { name, hash, maybe_length }); return adopt_own<AlgorithmParams>(*new HmacImportParams { hash, maybe_length });
} }
HmacKeyGenParams::~HmacKeyGenParams() = default; HmacKeyGenParams::~HmacKeyGenParams() = default;
@ -651,9 +598,6 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HmacKeyGenParams::from_val
{ {
auto& object = value.as_object(); auto& object = value.as_object();
auto name_value = TRY(object.get("name"));
auto name = TRY(name_value.to_string(vm));
auto hash_value = TRY(object.get("hash")); auto hash_value = TRY(object.get("hash"));
auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value)); auto hash = TRY(hash_algorithm_identifier_from_value(vm, hash_value));
@ -663,7 +607,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> HmacKeyGenParams::from_val
maybe_length = TRY(length_value.to_u32(vm)); maybe_length = TRY(length_value.to_u32(vm));
} }
return adopt_own<AlgorithmParams>(*new HmacKeyGenParams { name, hash, maybe_length }); return adopt_own<AlgorithmParams>(*new HmacKeyGenParams { hash, maybe_length });
} }
// https://w3c.github.io/webcrypto/#rsa-oaep-operations // https://w3c.github.io/webcrypto/#rsa-oaep-operations

View file

@ -45,11 +45,12 @@ struct HashAlgorithmIdentifier : public AlgorithmIdentifier {
// https://w3c.github.io/webcrypto/#algorithm-overview // https://w3c.github.io/webcrypto/#algorithm-overview
struct AlgorithmParams { struct AlgorithmParams {
virtual ~AlgorithmParams(); virtual ~AlgorithmParams();
explicit AlgorithmParams(String name) explicit AlgorithmParams()
: name(move(name))
{ {
} }
// NOTE: this is initialized when normalizing the algorithm name as the spec requests.
// It must not be set in `from_value`.
String name; String name;
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value); static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
@ -58,9 +59,8 @@ struct AlgorithmParams {
// https://w3c.github.io/webcrypto/#aes-cbc // https://w3c.github.io/webcrypto/#aes-cbc
struct AesCbcParams : public AlgorithmParams { struct AesCbcParams : public AlgorithmParams {
virtual ~AesCbcParams() override; virtual ~AesCbcParams() override;
AesCbcParams(String name, ByteBuffer iv) AesCbcParams(ByteBuffer iv)
: AlgorithmParams(move(name)) : iv(move(iv))
, iv(move(iv))
{ {
} }
@ -72,9 +72,8 @@ struct AesCbcParams : public AlgorithmParams {
// https://w3c.github.io/webcrypto/#dfn-AesCtrParams // https://w3c.github.io/webcrypto/#dfn-AesCtrParams
struct AesCtrParams : public AlgorithmParams { struct AesCtrParams : public AlgorithmParams {
virtual ~AesCtrParams() override; virtual ~AesCtrParams() override;
AesCtrParams(String name, ByteBuffer counter, u8 length) AesCtrParams(ByteBuffer counter, u8 length)
: AlgorithmParams(move(name)) : counter(move(counter))
, counter(move(counter))
, length(length) , length(length)
{ {
} }
@ -88,9 +87,8 @@ struct AesCtrParams : public AlgorithmParams {
// https://w3c.github.io/webcrypto/#dfn-AesGcmParams // https://w3c.github.io/webcrypto/#dfn-AesGcmParams
struct AesGcmParams : public AlgorithmParams { struct AesGcmParams : public AlgorithmParams {
virtual ~AesGcmParams() override; virtual ~AesGcmParams() override;
AesGcmParams(String name, ByteBuffer iv, Optional<ByteBuffer> additional_data, Optional<u8> tag_length) AesGcmParams(ByteBuffer iv, Optional<ByteBuffer> additional_data, Optional<u8> tag_length)
: AlgorithmParams(move(name)) : iv(move(iv))
, iv(move(iv))
, additional_data(move(additional_data)) , additional_data(move(additional_data))
, tag_length(tag_length) , tag_length(tag_length)
{ {
@ -106,9 +104,8 @@ struct AesGcmParams : public AlgorithmParams {
// https://w3c.github.io/webcrypto/#hkdf-params // https://w3c.github.io/webcrypto/#hkdf-params
struct HKDFParams : public AlgorithmParams { struct HKDFParams : public AlgorithmParams {
virtual ~HKDFParams() override; virtual ~HKDFParams() override;
HKDFParams(String name, HashAlgorithmIdentifier hash, ByteBuffer salt, ByteBuffer info) HKDFParams(HashAlgorithmIdentifier hash, ByteBuffer salt, ByteBuffer info)
: AlgorithmParams(move(name)) : hash(move(hash))
, hash(move(hash))
, salt(move(salt)) , salt(move(salt))
, info(move(info)) , info(move(info))
{ {
@ -124,9 +121,8 @@ struct HKDFParams : public AlgorithmParams {
// https://w3c.github.io/webcrypto/#pbkdf2-params // https://w3c.github.io/webcrypto/#pbkdf2-params
struct PBKDF2Params : public AlgorithmParams { struct PBKDF2Params : public AlgorithmParams {
virtual ~PBKDF2Params() override; virtual ~PBKDF2Params() override;
PBKDF2Params(String name, ByteBuffer salt, u32 iterations, HashAlgorithmIdentifier hash) PBKDF2Params(ByteBuffer salt, u32 iterations, HashAlgorithmIdentifier hash)
: AlgorithmParams(move(name)) : salt(move(salt))
, salt(move(salt))
, iterations(iterations) , iterations(iterations)
, hash(move(hash)) , hash(move(hash))
{ {
@ -143,9 +139,8 @@ struct PBKDF2Params : public AlgorithmParams {
struct RsaKeyGenParams : public AlgorithmParams { struct RsaKeyGenParams : public AlgorithmParams {
virtual ~RsaKeyGenParams() override; virtual ~RsaKeyGenParams() override;
RsaKeyGenParams(String name, u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent) RsaKeyGenParams(u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent)
: AlgorithmParams(move(name)) : modulus_length(modulus_length)
, modulus_length(modulus_length)
, public_exponent(move(public_exponent)) , public_exponent(move(public_exponent))
{ {
} }
@ -161,8 +156,8 @@ struct RsaKeyGenParams : public AlgorithmParams {
struct RsaHashedKeyGenParams : public RsaKeyGenParams { struct RsaHashedKeyGenParams : public RsaKeyGenParams {
virtual ~RsaHashedKeyGenParams() override; virtual ~RsaHashedKeyGenParams() override;
RsaHashedKeyGenParams(String name, u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent, HashAlgorithmIdentifier hash) RsaHashedKeyGenParams(u32 modulus_length, ::Crypto::UnsignedBigInteger public_exponent, HashAlgorithmIdentifier hash)
: RsaKeyGenParams(move(name), modulus_length, move(public_exponent)) : RsaKeyGenParams(modulus_length, move(public_exponent))
, hash(move(hash)) , hash(move(hash))
{ {
} }
@ -176,9 +171,8 @@ struct RsaHashedKeyGenParams : public RsaKeyGenParams {
struct RsaHashedImportParams : public AlgorithmParams { struct RsaHashedImportParams : public AlgorithmParams {
virtual ~RsaHashedImportParams() override; virtual ~RsaHashedImportParams() override;
RsaHashedImportParams(String name, HashAlgorithmIdentifier hash) RsaHashedImportParams(HashAlgorithmIdentifier hash)
: AlgorithmParams(move(name)) : hash(move(hash))
, hash(move(hash))
{ {
} }
@ -191,9 +185,8 @@ struct RsaHashedImportParams : public AlgorithmParams {
struct RsaOaepParams : public AlgorithmParams { struct RsaOaepParams : public AlgorithmParams {
virtual ~RsaOaepParams() override; virtual ~RsaOaepParams() override;
RsaOaepParams(String name, ByteBuffer label) RsaOaepParams(ByteBuffer label)
: AlgorithmParams(move(name)) : label(move(label))
, label(move(label))
{ {
} }
@ -206,9 +199,8 @@ struct RsaOaepParams : public AlgorithmParams {
struct EcdsaParams : public AlgorithmParams { struct EcdsaParams : public AlgorithmParams {
virtual ~EcdsaParams() override; virtual ~EcdsaParams() override;
EcdsaParams(String name, HashAlgorithmIdentifier hash) EcdsaParams(HashAlgorithmIdentifier hash)
: AlgorithmParams(move(name)) : hash(move(hash))
, hash(move(hash))
{ {
} }
@ -221,9 +213,8 @@ struct EcdsaParams : public AlgorithmParams {
struct EcKeyGenParams : public AlgorithmParams { struct EcKeyGenParams : public AlgorithmParams {
virtual ~EcKeyGenParams() override; virtual ~EcKeyGenParams() override;
EcKeyGenParams(String name, NamedCurve named_curve) EcKeyGenParams(NamedCurve named_curve)
: AlgorithmParams(move(name)) : named_curve(move(named_curve))
, named_curve(move(named_curve))
{ {
} }
@ -236,9 +227,8 @@ struct EcKeyGenParams : public AlgorithmParams {
struct AesKeyGenParams : public AlgorithmParams { struct AesKeyGenParams : public AlgorithmParams {
virtual ~AesKeyGenParams() override; virtual ~AesKeyGenParams() override;
AesKeyGenParams(String name, u16 length) AesKeyGenParams(u16 length)
: AlgorithmParams(move(name)) : length(length)
, length(length)
{ {
} }
@ -251,9 +241,8 @@ struct AesKeyGenParams : public AlgorithmParams {
struct AesDerivedKeyParams : public AlgorithmParams { struct AesDerivedKeyParams : public AlgorithmParams {
virtual ~AesDerivedKeyParams() override; virtual ~AesDerivedKeyParams() override;
AesDerivedKeyParams(String name, u16 length) AesDerivedKeyParams(u16 length)
: AlgorithmParams(move(name)) : length(length)
, length(length)
{ {
} }
@ -266,9 +255,8 @@ struct AesDerivedKeyParams : public AlgorithmParams {
struct HmacImportParams : public AlgorithmParams { struct HmacImportParams : public AlgorithmParams {
virtual ~HmacImportParams() override; virtual ~HmacImportParams() override;
HmacImportParams(String name, HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length) HmacImportParams(HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length)
: AlgorithmParams(move(name)) : hash(move(hash))
, hash(move(hash))
, length(length) , length(length)
{ {
} }
@ -283,9 +271,8 @@ struct HmacImportParams : public AlgorithmParams {
struct HmacKeyGenParams : public AlgorithmParams { struct HmacKeyGenParams : public AlgorithmParams {
virtual ~HmacKeyGenParams() override; virtual ~HmacKeyGenParams() override;
HmacKeyGenParams(String name, HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length) HmacKeyGenParams(HashAlgorithmIdentifier hash, Optional<WebIDL::UnsignedLong> length)
: AlgorithmParams(move(name)) : hash(move(hash))
, hash(move(hash))
, length(length) , length(length)
{ {
} }
@ -580,9 +567,8 @@ private:
struct EcdhKeyDeriveParams : public AlgorithmParams { struct EcdhKeyDeriveParams : public AlgorithmParams {
virtual ~EcdhKeyDeriveParams() override; virtual ~EcdhKeyDeriveParams() override;
EcdhKeyDeriveParams(String name, CryptoKey& public_key) EcdhKeyDeriveParams(CryptoKey& public_key)
: AlgorithmParams(move(name)) : public_key(public_key)
, public_key(public_key)
{ {
} }
@ -594,9 +580,8 @@ struct EcdhKeyDeriveParams : public AlgorithmParams {
struct EcKeyImportParams : public AlgorithmParams { struct EcKeyImportParams : public AlgorithmParams {
virtual ~EcKeyImportParams() override; virtual ~EcKeyImportParams() override;
EcKeyImportParams(String name, String named_curve) EcKeyImportParams(String named_curve)
: AlgorithmParams(move(name)) : named_curve(move(named_curve))
, named_curve(move(named_curve))
{ {
} }

View file

@ -100,6 +100,8 @@ WebIDL::ExceptionOr<NormalizedAlgorithmAndParameter> normalize_an_algorithm(JS::
// 5. If registeredAlgorithms contains a key that is a case-insensitive string match for algName: // 5. If registeredAlgorithms contains a key that is a case-insensitive string match for algName:
if (auto it = registered_algorithms.find(algorithm_name); it != registered_algorithms.end()) { if (auto it = registered_algorithms.find(algorithm_name); it != registered_algorithms.end()) {
// 1. Set algName to the value of the matching key. // 1. Set algName to the value of the matching key.
algorithm_name = it->key;
// 2. Let desiredType be the IDL dictionary type stored at algName in registeredAlgorithms. // 2. Let desiredType be the IDL dictionary type stored at algName in registeredAlgorithms.
desired_type = it->value; desired_type = it->value;
} else { } else {
@ -110,7 +112,6 @@ WebIDL::ExceptionOr<NormalizedAlgorithmAndParameter> normalize_an_algorithm(JS::
// 8. Let normalizedAlgorithm be the result of converting the ECMAScript object represented by alg // 8. Let normalizedAlgorithm be the result of converting the ECMAScript object represented by alg
// to the IDL dictionary type desiredType, as defined by [WebIDL]. // to the IDL dictionary type desiredType, as defined by [WebIDL].
// 9. Set the name attribute of normalizedAlgorithm to algName.
// 10. If an error occurred, return the error and terminate this algorithm. // 10. If an error occurred, return the error and terminate this algorithm.
// 11. Let dictionaries be a list consisting of the IDL dictionary type desiredType // 11. Let dictionaries be a list consisting of the IDL dictionary type desiredType
// and all of desiredType's inherited dictionaries, in order from least to most derived. // and all of desiredType's inherited dictionaries, in order from least to most derived.
@ -118,6 +119,11 @@ WebIDL::ExceptionOr<NormalizedAlgorithmAndParameter> normalize_an_algorithm(JS::
// Note: All of these steps are handled by the create_methods and parameter_from_value methods. // Note: All of these steps are handled by the create_methods and parameter_from_value methods.
auto methods = desired_type.create_methods(realm); auto methods = desired_type.create_methods(realm);
auto parameter = TRY(desired_type.parameter_from_value(vm, algorithm.get<GC::Root<JS::Object>>())); auto parameter = TRY(desired_type.parameter_from_value(vm, algorithm.get<GC::Root<JS::Object>>()));
// 9. Set the name attribute of normalizedAlgorithm to algName.
VERIFY(parameter->name.is_empty());
parameter->name = algorithm_name;
auto normalized_algorithm = NormalizedAlgorithmAndParameter { move(methods), move(parameter) }; auto normalized_algorithm = NormalizedAlgorithmAndParameter { move(methods), move(parameter) };
// 13. Return normalizedAlgorithm. // 13. Return normalizedAlgorithm.

View file

@ -6,8 +6,8 @@ Rerun
Found 18 tests Found 18 tests
16 Pass 17 Pass
2 Fail 1 Fail
Details Details
Result Test Name MessagePass setup - define tests Result Test Name MessagePass setup - define tests
Pass X448 key derivation checks for all-zero value result with a key of order 0 Pass X448 key derivation checks for all-zero value result with a key of order 0
@ -16,7 +16,7 @@ Pass X448 key derivation checks for all-zero value result with a key of order p-
Pass X448 key derivation checks for all-zero value result with a key of order p (=0, order 4) Pass X448 key derivation checks for all-zero value result with a key of order p (=0, order 4)
Pass X448 key derivation checks for all-zero value result with a key of order p+1 (=1, order 1) Pass X448 key derivation checks for all-zero value result with a key of order p+1 (=1, order 1)
Pass X448 good parameters Pass X448 good parameters
Fail X448 mixed case parameters Pass X448 mixed case parameters
Pass X448 short result Pass X448 short result
Fail X448 non-multiple of 8 bits Fail X448 non-multiple of 8 bits
Pass X448 missing public property Pass X448 missing public property

View file

@ -6,8 +6,8 @@ Rerun
Found 40 tests Found 40 tests
23 Pass 25 Pass
17 Fail 15 Fail
Details Details
Result Test Name MessagePass setup - define tests Result Test Name MessagePass setup - define tests
Fail P-521 good parameters Fail P-521 good parameters
@ -24,7 +24,7 @@ Fail P-521 public property value is a private key
Fail P-521 public property value is a secret key Fail P-521 public property value is a secret key
Fail P-521 asking for too many bits Fail P-521 asking for too many bits
Pass P-256 good parameters Pass P-256 good parameters
Fail P-256 mixed case parameters Pass P-256 mixed case parameters
Pass P-256 short result Pass P-256 short result
Fail P-256 non-multiple of 8 bits Fail P-256 non-multiple of 8 bits
Pass P-256 missing public curve Pass P-256 missing public curve
@ -37,7 +37,7 @@ Pass P-256 public property value is a private key
Pass P-256 public property value is a secret key Pass P-256 public property value is a secret key
Fail P-256 asking for too many bits Fail P-256 asking for too many bits
Pass P-384 good parameters Pass P-384 good parameters
Fail P-384 mixed case parameters Pass P-384 mixed case parameters
Pass P-384 short result Pass P-384 short result
Fail P-384 non-multiple of 8 bits Fail P-384 non-multiple of 8 bits
Pass P-384 missing public curve Pass P-384 missing public curve

View file

@ -6,8 +6,8 @@ Rerun
Found 31 tests Found 31 tests
21 Pass 23 Pass
10 Fail 8 Fail
Details Details
Result Test Name MessagePass setup - define tests Result Test Name MessagePass setup - define tests
Fail P-521 good parameters Fail P-521 good parameters
@ -21,7 +21,7 @@ Fail P-521 base key is not a private key
Fail P-521 public property value is a private key Fail P-521 public property value is a private key
Fail P-521 public property value is a secret key Fail P-521 public property value is a secret key
Pass P-256 good parameters Pass P-256 good parameters
Fail P-256 mixed case parameters Pass P-256 mixed case parameters
Pass P-256 missing public curve Pass P-256 missing public curve
Pass P-256 public property of algorithm is not a CryptoKey Pass P-256 public property of algorithm is not a CryptoKey
Pass P-256 mismatched curves Pass P-256 mismatched curves
@ -31,7 +31,7 @@ Pass P-256 base key is not a private key
Pass P-256 public property value is a private key Pass P-256 public property value is a private key
Pass P-256 public property value is a secret key Pass P-256 public property value is a secret key
Pass P-384 good parameters Pass P-384 good parameters
Fail P-384 mixed case parameters Pass P-384 mixed case parameters
Pass P-384 missing public curve Pass P-384 missing public curve
Pass P-384 public property of algorithm is not a CryptoKey Pass P-384 public property of algorithm is not a CryptoKey
Pass P-384 mismatched curves Pass P-384 mismatched curves