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

Unified Diff: LayoutTests/crypto/hmac-import-jwk.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/crypto/hmac-generate-key-expected.txt ('k') | LayoutTests/crypto/hmac-import-jwk-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/hmac-import-jwk.html
diff --git a/LayoutTests/crypto/hmac-import-jwk.html b/LayoutTests/crypto/hmac-import-jwk.html
new file mode 100644
index 0000000000000000000000000000000000000000..93f7273521fcfccf07c6b6a8691c0539a77c4226
--- /dev/null
+++ b/LayoutTests/crypto/hmac-import-jwk.html
@@ -0,0 +1,54 @@
+<!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 a JWK key for HMAC.");
+
+jsTestIsAsync = true;
+
+var nonExtractable = false;
+var extractable = true;
+
+var hmacKey = {
+ "kty": "oct",
+ "alg": "HS256",
+ "use": "sig",
+ "ext": false,
+ "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
+};
+
+var hmacKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(hmacKey));
+
+debug("Importing a key...\n");
+crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, {name: "HMAC", hash: {name: "SHA-256"}}, nonExtractable, ["sign", "verify"]).then(function(result) {
+ key = result;
+
+ shouldBe("key.type", "'secret'");
+ shouldBe("key.extractable", "false");
+ shouldBe("key.algorithm.name", "'HMAC'");
+ shouldBe("key.algorithm.length", "256");
+ shouldBe("key.usages", '["sign", "verify"]');
+
+ debug("\nUsing the key to sign message 'foo'...");
+ return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
+}).then(function(result) {
+ signature = result;
+ shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
+
+ debug("\nVerifying the signature...");
+ return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
+}).then(function(result) {
+ verificationResult = result;
+ shouldBe("verificationResult", "true");
+}).then(finishJSTest, failAndFinishJSTest);
+</script>
+
+</body>
+</html>
« no previous file with comments | « LayoutTests/crypto/hmac-generate-key-expected.txt ('k') | LayoutTests/crypto/hmac-import-jwk-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698