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

Unified Diff: LayoutTests/crypto/ecdsa-sign-verify.html

Issue 707753002: WebCrypto: Add LayoutTests for ECDSA. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase onto master Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/crypto/ecdsa-sign-verify.html
diff --git a/LayoutTests/crypto/ecdsa-sign-verify.html b/LayoutTests/crypto/ecdsa-sign-verify.html
new file mode 100644
index 0000000000000000000000000000000000000000..7a6f6959e49854ef7e74470a8c4829eb29529cc4
--- /dev/null
+++ b/LayoutTests/crypto/ecdsa-sign-verify.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing an EC key for ECDSA.");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+
+var publicKeyJSON = {
+ "kty": "EC",
+ "crv": "P-256",
+ "x": "fBEMZtz9qAf25p5F3bPHT2mhSE0gPo3Frajpqd18s8c",
+ "y": "DfRImG5RveXRV2-ZkB-cLGqAakf9kHZDpyuDVZfvyMY"
+};
+
+var privateKeyJSON = {
+ "kty": "EC",
+ "crv": "P-256",
+ "d": "H-M5UMX0YRJK6ZLCvf3xxzsWFfVxvVZ-YNGaofSM30I",
+ "x": "fBEMZtz9qAf25p5F3bPHT2mhSE0gPo3Frajpqd18s8c",
+ "y": "DfRImG5RveXRV2-ZkB-cLGqAakf9kHZDpyuDVZfvyMY"
+};
+
+var data = asciiToUint8Array("Hello, world!");
+
+debug("Importing a public key...");
+crypto.subtle.importKey("jwk", publicKeyJSON, { name: "ECDSA", namedCurve: "P-256" }, extractable, ["verify"]).then(function(result) {
+ publicKey = result;
+ debug("\nImporting a private key...");
+ return crypto.subtle.importKey("jwk", privateKeyJSON, { name: "ECDSA", namedCurve: "P-256" }, extractable, ["sign"]);
+}).then(function(result) {
+ privateKey = result;
+ debug("\nSigning some text...");
+ return crypto.subtle.sign({ name: "ECDSA", hash: { name: "SHA-1" } }, privateKey, data);
+}).then(function(result) {
+ signature = result;
+
+ debug("\nVerifying the signature...");
+ return crypto.subtle.verify({ name: "ECDSA", hash: { name: "SHA-1" } }, publicKey, signature, data);
+}).then(function(result) {
+ verificationResult = result;
+ shouldBe("verificationResult", "true");
+ debug("\nVerifying a bad signature...");
+ return crypto.subtle.verify({ name: "ECDSA", hash: { name: "SHA-1" } }, publicKey, new Uint8Array(256), data);
+}).then(function(result) {
+ verificationResult = result;
+ shouldBe("verificationResult", "false");
+}).then(finishJSTest, failAndFinishJSTest);
+</script>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698