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

Side by Side Diff: LayoutTests/crypto/hmac-import-jwk.html

Issue 336173002: [webcrypto] Require importKey() for JWK to provide data as a Javascript object rather than a JSON a… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update additional tests 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
« no previous file with comments | « LayoutTests/crypto/hmac-export-key.html ('k') | LayoutTests/crypto/import-jwk.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../resources/js-test.js"></script> 4 <script src="../resources/js-test.js"></script>
5 <script src="resources/common.js"></script> 5 <script src="resources/common.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <p id="description"></p> 8 <p id="description"></p>
9 <div id="console"></div> 9 <div id="console"></div>
10 10
11 <script> 11 <script>
12 description("Test importing a JWK key for HMAC."); 12 description("Test importing a JWK key for HMAC.");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 var nonExtractable = false; 16 var nonExtractable = false;
17 var extractable = true; 17 var extractable = true;
18 18
19 var hmacKey = { 19 var hmacKey = {
20 "kty": "oct", 20 "kty": "oct",
21 "alg": "HS256", 21 "alg": "HS256",
22 "use": "sig", 22 "use": "sig",
23 "ext": false, 23 "ext": false,
24 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs" 24 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
25 }; 25 };
26 26
27 var hmacKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(hmacKey));
28
29 debug("Importing a key...\n"); 27 debug("Importing a key...\n");
30 crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, {name: "HMAC", hash: {name: "SHA-256"}}, nonExtractable, ["sign", "verify"]).then(function(result) { 28 crypto.subtle.importKey("jwk", hmacKey, {name: "HMAC", hash: {name: "SHA-256"}}, nonExtractable, ["sign", "verify"]).then(function(result) {
31 key = result; 29 key = result;
32 30
33 shouldBe("key.type", "'secret'"); 31 shouldBe("key.type", "'secret'");
34 shouldBe("key.extractable", "false"); 32 shouldBe("key.extractable", "false");
35 shouldBe("key.algorithm.name", "'HMAC'"); 33 shouldBe("key.algorithm.name", "'HMAC'");
36 shouldBe("key.algorithm.length", "256"); 34 shouldBe("key.algorithm.length", "256");
37 shouldBe("key.usages", '["sign", "verify"]'); 35 shouldBe("key.usages", '["sign", "verify"]');
38 36
39 debug("\nUsing the key to sign message 'foo'..."); 37 debug("\nUsing the key to sign message 'foo'...");
40 return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo')); 38 return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
41 }).then(function(result) { 39 }).then(function(result) {
42 signature = result; 40 signature = result;
43 shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2 da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'"); 41 shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2 da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
44 42
45 debug("\nVerifying the signature..."); 43 debug("\nVerifying the signature...");
46 return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('f oo')); 44 return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('f oo'));
47 }).then(function(result) { 45 }).then(function(result) {
48 verificationResult = result; 46 verificationResult = result;
49 shouldBe("verificationResult", "true"); 47 shouldBe("verificationResult", "true");
50 }).then(finishJSTest, failAndFinishJSTest); 48 }).then(finishJSTest, failAndFinishJSTest);
51 </script> 49 </script>
52 50
53 </body> 51 </body>
54 </html> 52 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/hmac-export-key.html ('k') | LayoutTests/crypto/import-jwk.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698