Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: LayoutTests/crypto/hmac-export-key.html

Issue 298023002: [webcrypto] Import WebKit's webcrypto tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove FIXME for unrecognized jwk usages (supported now) Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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>
10
11 <script>
12 description("Test exporting an AES key.");
13
14 jsTestIsAsync = true;
15
16 var extractable = true;
17 var nonExtractable = false;
18
19 var jwkKey = {
20 "kty": "oct",
21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
22 };
23
24 var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
25
26 debug("Importing a JWK key...");
27 crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: {name: "SHA-256"} }, extractable, ["sign", "verify"]).then(function(result) {
28 key = result;
29
30 return crypto.subtle.exportKey(null, key);
31 }).then(failAndFinishJSTest, function(result) {
32 logError(result);
33 return crypto.subtle.exportKey(undefined, key);
34 }).then(failAndFinishJSTest, function(result) {
35 logError(result);
36 return crypto.subtle.exportKey({}, key);
37 }).then(failAndFinishJSTest, function(result) {
38 logError(result);
39 return crypto.subtle.exportKey("", key);
40 }).then(failAndFinishJSTest, function(result) {
41 logError(result);
42 return crypto.subtle.exportKey("foobar", key);
43 }).then(failAndFinishJSTest, function(result) {
44 logError(result);
45
46 debug("Exporting the key as raw data...");
47 return crypto.subtle.exportKey("raw", key);
48 }, failAndFinishJSTest).then(function(result) {
49 exportedData = result;
50 shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b 7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
51
52 debug("Exporting the key as JWK...");
53 return crypto.subtle.exportKey("jwk", key);
54 }).then(function(result) {
55 exportedJWK = JSON.parse(bytesToASCIIString(result));
56 shouldBe("exportedJWK.kty", "'oct'");
57 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'");
58 shouldBe("exportedJWK.alg", "'HS256'");
59 shouldBe("exportedJWK.ext", "true");
60 shouldBe("exportedJWK.use", "undefined");
61 shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
62
63 debug("\nImporting a key that's not extractable...");
64 return crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", h ash: {name: "SHA-256"} }, nonExtractable, ["sign", "verify"]);
65 }, failAndFinishJSTest).then(function(result) {
66 key = result;
67
68 debug("\nTrying to export as raw...");
69 return crypto.subtle.exportKey("raw", key);
70 }).then(function(result) {
71 testFailed("Promise wasn't rejected");
72 finishJSTest();
73 }, function(result) {
74 logError(result);
75 testPassed("Rejected, as expected");
76
77 debug("Trying to export as jwk...");
78 return crypto.subtle.exportKey("jwk", key);
79 }).then(function(result) {
80 testFailed("Promise wasn't rejected");
81 finishJSTest();
82 }, function(result) {
83 logError(result);
84 testPassed("Rejected, as expected");
85
86 finishJSTest();
87 });
88 </script>
89
90 </body>
91 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/array-buffer-view-offset-expected.txt ('k') | LayoutTests/crypto/hmac-export-key-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698