Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion builtins/web/crypto/crypto-key.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class CryptoKeyUsages {
[[nodiscard]] bool canOnlyDecrypt() const { return this->mask == decrypt_flag; };
[[nodiscard]] bool canOnlySign() const { return this->mask == sign_flag; };
[[nodiscard]] bool canOnlyVerify() const { return this->mask == verify_flag; };
[[nodiscard]] bool canOnlySignOrVerify() const { return (this->mask & (sign_flag | verify_flag)) != 0; };
[[nodiscard]] bool canOnlySignOrVerify() const {
return this->mask == sign_flag || this->mask == verify_flag ||
this->mask == (sign_flag | verify_flag);
};
[[nodiscard]] bool canOnlyDeriveKey() const { return this->mask == derive_key_flag; };
[[nodiscard]] bool canOnlyDeriveBits() const { return this->mask == derive_bits_flag; };
[[nodiscard]] bool canOnlyWrapKey() const { return this->mask == wrap_key_flag; };
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/crypto/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,19 @@ export const handler = serveTest(async (t) => {
deepStrictEqual(key.usages, ["sign", "verify"], `key.usages`);
}
});
await t.test("subtle.importKey.HMAC-non-sign-or-verify-usage", async () => {
for (const usages of [[], ["encrypt"], ["sign", "encrypt"], ["verify", "deriveBits"]]) {
await rejects(async () => {
await crypto.subtle.importKey(
"raw",
new Uint8Array([1, 0, 1]),
{ name: "HMAC", hash: "SHA-256" },
false,
usages,
);
}, DOMException, undefined, "SyntaxError");
}
});
await t.test("subtle.importKey.JWK-HS256-Public", async () => {
const key = await crypto.subtle.importKey(
"jwk",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2136,16 +2136,16 @@
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), Ed25519, true, [sign])": {
"status": "FAIL"
"status": "PASS"
Comment thread
andreiltd marked this conversation as resolved.
},
"Missing JWK 'kty' parameter: importKey(jwk(private), Ed25519, false, [sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), Ed25519, true, [sign, sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), Ed25519, false, [sign, sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'crv' parameter: importKey(jwk (public) , Ed25519, true, [verify])": {
"status": "PASS"
Expand All @@ -2172,16 +2172,16 @@
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), {name: Ed25519}, true, [sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), {name: Ed25519}, false, [sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), {name: Ed25519}, true, [sign, sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'kty' parameter: importKey(jwk(private), {name: Ed25519}, false, [sign, sign])": {
"status": "FAIL"
"status": "PASS"
},
"Missing JWK 'crv' parameter: importKey(jwk (public) , {name: Ed25519}, true, [verify])": {
"status": "PASS"
Expand Down
Loading