4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Test exporting keys with various usages to JWK.");
16 var extractable
= true;
18 var aesKeyAsArrayBuffer
= Base64URL
.parse("jnOw99oOZFLIEPMrgJB55Q");
19 var hmacKeyAsArrayBuffer
= Base64URL
.parse("ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs");
21 function testWithAESCBC(usages
, expectedKeyOps
)
23 return crypto
.subtle
.importKey("raw", aesKeyAsArrayBuffer
, {name
: "AES-CBC"}, extractable
, usages
).then(function(result
) {
24 return crypto
.subtle
.exportKey("jwk", result
);
25 }).then(function(result
) {
28 shouldBe("jwk.use", "undefined");
29 shouldBe("jwk.key_ops", JSON
.stringify(expectedKeyOps
));
34 function testWithHMAC(usages
, expectedKeyOps
)
36 return crypto
.subtle
.importKey("raw", hmacKeyAsArrayBuffer
, {name
: 'hmac', hash
: {name
: 'sha-256'}}, extractable
, usages
).then(function(result
) {
37 return crypto
.subtle
.exportKey("jwk", result
);
38 }).then(function(result
) {
41 shouldBe("jwk.use", "undefined");
42 shouldBe("jwk.key_ops", JSON
.stringify(expectedKeyOps
));
48 testWithAESCBC(["encrypt"], ["encrypt"]),
49 testWithAESCBC(["decrypt"], ["decrypt"]),
50 testWithAESCBC(["encrypt", "decrypt"], ["encrypt", "decrypt"]),
51 testWithAESCBC(["wrapKey"], ["wrapKey"]),
52 testWithAESCBC(["unwrapKey"], ["unwrapKey"]),
53 testWithAESCBC(["wrapKey", "unwrapKey"], ["wrapKey", "unwrapKey"]),
54 testWithAESCBC(["encrypt", "decrypt", "wrapKey"], ["encrypt", "decrypt", "wrapKey"]),
55 testWithAESCBC(["encrypt", "decrypt", "wrapKey", "unwrapKey"], ["encrypt", "decrypt", "wrapKey", "unwrapKey"]),
56 testWithHMAC(["sign"], ["sign"]),
57 testWithHMAC(["verify"], ["verify"]),
58 testWithHMAC(["sign", "verify"], ["sign", "verify"]),
59 ]).then(finishJSTest
, failAndFinishJSTest
);