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

Side by Side Diff: third_party/WebKit/LayoutTests/crypto/subtle/ecdh/import-export-raw.html

Issue 2162303002: [webcrypto] Add support for import/export of "raw" formatted EC keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usage_order
Patch Set: address feedback Created 4 years, 4 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
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 importing and exporting an EC public key in raw format.");
13
14 jsTestIsAsync = true;
15
16 // P-256 key in uncompressed form
17 var kUncompressedHex = "044EA34391AA73885454BC45DF3FDCC4A70262FA4621FFE25B579059 0C340A4BD9265EF2B3F9A86E2959A960D90323465D60CD4A90D314C5DE3F869AD0D4BF6C10";
18
19 // The same key as above but in compressed form.
20 var kCompressedHex = "024ea34391aa73885454bc45df3fdcc4a70262fa4621ffe25b5790590c 340a4bd9";
21
22 var algorithm = {name: "ECDH", namedCurve: "P-256"};
23 var extractable = true;
24
25 debug("Importing raw (uncompressed) public key...");
26 crypto.subtle.importKey("raw", hexStringToUint8Array(kUncompressedHex), algorith m, extractable, []).then(function(result) {
27 publicKey = result;
28 shouldBe("publicKey.toString()", "'[object CryptoKey]'");
29 shouldBe("publicKey.type", "'public'");
30 shouldBe("publicKey.usages", "[]");
31 shouldBe("publicKey.algorithm.name", "'ECDH'");
32 shouldBe("publicKey.algorithm.namedCurve", "'P-256'");
33
34 debug("Exporting to raw...");
35 return crypto.subtle.exportKey("raw", publicKey);
36 }).then(function(result) {
37 bytesShouldMatchHexString("Exported to raw", kUncompressedHex, result)
38
39 debug("Importing raw (compressed) public key...");
40 return crypto.subtle.importKey("raw", hexStringToUint8Array(kCompressedHex), algorithm, extractable, []);
41 }).then(function(result) {
42 publicKey = result;
43 shouldBe("publicKey.toString()", "'[object CryptoKey]'");
44 shouldBe("publicKey.type", "'public'");
45 shouldBe("publicKey.usages", "[]");
46 shouldBe("publicKey.algorithm.name", "'ECDH'");
47 shouldBe("publicKey.algorithm.namedCurve", "'P-256'");
48
49 debug("Exporting to raw...");
50 return crypto.subtle.exportKey("raw", publicKey);
51 }).then(function(result) {
52 bytesShouldMatchHexString("Exported to raw", kUncompressedHex, result)
53
54 debug("Importing invalid raw public key...");
55 return crypto.subtle.importKey("raw", hexStringToUint8Array("040708"), algor ithm, extractable, []);
56 }).then(failAndFinishJSTest, function(result) {
57 logError(result);
58 }).then(finishJSTest, failAndFinishJSTest);
59 </script>
60
61 </body>
62 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698