Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / jwk-export-use-values.html
blobdfbd209b3a446bc62704530945d45bdb69fc4c91
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Test exporting keys with various usages to JWK.");
14 jsTestIsAsync = true;
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) {
26 jwk = result;
27 debug(usages + ":");
28 shouldBe("jwk.use", "undefined");
29 shouldBe("jwk.key_ops", JSON.stringify(expectedKeyOps));
30 debug("");
31 });
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) {
39 jwk = result;
40 debug(usages + ":");
41 shouldBe("jwk.use", "undefined");
42 shouldBe("jwk.key_ops", JSON.stringify(expectedKeyOps));
43 debug("");
44 });
47 Promise.all([
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);
60 </script>
62 </body>
63 </html>