mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibWeb: Correctly set the key_usages on HMAC export
This commit is contained in:
parent
1c77135948
commit
19ee8ddec2
Notes:
github-actions[bot]
2024-11-14 18:49:14 +00:00
Author: https://github.com/stelar7
Commit: 19ee8ddec2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2339
Reviewed-by: https://github.com/gmta
3 changed files with 27 additions and 11 deletions
|
@ -3589,8 +3589,6 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> HMAC::import_key(Web::Crypto::A
|
||||||
// https://w3c.github.io/webcrypto/#hmac-operations
|
// https://w3c.github.io/webcrypto/#hmac-operations
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> HMAC::export_key(Bindings::KeyFormat format, JS::NonnullGCPtr<CryptoKey> key)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> HMAC::export_key(Bindings::KeyFormat format, JS::NonnullGCPtr<CryptoKey> key)
|
||||||
{
|
{
|
||||||
auto& vm = m_realm->vm();
|
|
||||||
|
|
||||||
// 1. If the underlying cryptographic key material represented by the [[handle]] internal slot
|
// 1. If the underlying cryptographic key material represented by the [[handle]] internal slot
|
||||||
// of key cannot be accessed, then throw an OperationError.
|
// of key cannot be accessed, then throw an OperationError.
|
||||||
// NOTE: In our impl this is always accessible
|
// NOTE: In our impl this is always accessible
|
||||||
|
@ -3657,15 +3655,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> HMAC::export_key(Bindings::Key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the key_ops attribute of jwk to equal the usages attribute of key.
|
// Set the key_ops attribute of jwk to equal the usages attribute of key.
|
||||||
auto key_usages = verify_cast<JS::Array>(key->usages());
|
jwk.key_ops = Vector<String> {};
|
||||||
auto key_usages_length = MUST(MUST(key_usages->get(vm.names.length)).to_length(vm));
|
jwk.key_ops->ensure_capacity(key->internal_usages().size());
|
||||||
for (auto i = 0u; i < key_usages_length; ++i) {
|
for (auto const& usage : key->internal_usages()) {
|
||||||
auto usage = key_usages->get(i);
|
jwk.key_ops->append(Bindings::idl_enum_to_string(usage));
|
||||||
if (!usage.has_value())
|
|
||||||
break;
|
|
||||||
|
|
||||||
auto usage_string = TRY(usage.value().to_string(vm));
|
|
||||||
jwk.key_ops->append(usage_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the ext attribute of jwk to equal the [[extractable]] internal slot of key.
|
// Set the ext attribute of jwk to equal the [[extractable]] internal slot of key.
|
||||||
|
|
1
Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-hmac.txt
Normal file
1
Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-hmac.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Does not crash.
|
22
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-hmac.html
Normal file
22
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-hmac.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest(async done => {
|
||||||
|
await crypto.subtle.exportKey(
|
||||||
|
"jwk",
|
||||||
|
await crypto.subtle.generateKey(
|
||||||
|
{
|
||||||
|
name: "HMAC",
|
||||||
|
hash: {
|
||||||
|
name: "SHA-512",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
!0,
|
||||||
|
["sign", "verify"]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
println("Does not crash.");
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue