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

Unified Diff: LayoutTests/crypto/clone-aesKey.html

Issue 195543002: [webcrypto] Implement structured clone of keys (blink-side). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix another comment Created 6 years, 9 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 | « no previous file | LayoutTests/crypto/clone-aesKey-expected.txt » ('j') | LayoutTests/crypto/resources/common.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/clone-aesKey.html
diff --git a/LayoutTests/crypto/clone-aesKey.html b/LayoutTests/crypto/clone-aesKey.html
new file mode 100644
index 0000000000000000000000000000000000000000..4899353ae55679c462e8f40f515edfe3e1278fda
--- /dev/null
+++ b/LayoutTests/crypto/clone-aesKey.html
@@ -0,0 +1,81 @@
+<!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("Tests structured cloning of AES keys");
+
+jsTestIsAsync = true;
+
+// Tests the 48 permutations of keys generated by:
+// kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData
+//
+// For practical reasons these tests are not exhaustive.
+
+var k128BitData = "30112233445566778899aabbccddeeff"
+var k192BitData = "800102030405060708090a0b0c0d0e0f1011121314151617";
+var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0e0f";
+
+var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM'];
+var kPossibleExtractable = [true, false];
+var kPossibleKeyUsages = [[], ['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrapKey', 'unwrapKey']];
+var kPossibleKeyData = [k128BitData, k192BitData, k256BitData];
+
+function runTest(algorithmName, extractable, keyUsages, keyData)
+{
+ var keyLengthBits = keyData.length * 4;
+
+ return crypto.subtle.importKey('raw', hexStringToUint8Array(keyData), { name: algorithmName },
+ extractable, keyUsages).then(function(result) {
+ importedKey = result;
+
+ shouldBe("importedKey.type", evalWrap("secret"));
jsbell 2014/03/13 20:16:07 This can be shouldBeEqualToString("importedKey.typ
+ shouldBe("importedKey.extractable", evalWrap(extractable));
jsbell 2014/03/13 20:16:07 Using the shouldBe() helpers is a pain with locals
eroman 2014/03/14 05:24:33 I ended up creating a wrapper function shouldEvalu
+ shouldBe("importedKey.algorithm.name", evalWrap(algorithmName));
+ shouldBe("importedKey.algorithm.length", evalWrap(keyLengthBits));
+ shouldBe("importedKey.usages.join(',')", evalWrap(keyUsages.join(",")));
+
+ clonedKey = cloneKeyAndLog(importedKey);
+
+ shouldBe("clonedKey.type", evalWrap("secret"));
+ shouldBe("clonedKey.extractable", evalWrap(extractable));
+ shouldBe("clonedKey.algorithm.name", evalWrap(algorithmName));
+ shouldBe("clonedKey.algorithm.length", evalWrap(keyLengthBits));
+ shouldBe("clonedKey.usages.join(',')", evalWrap(keyUsages.join(",")));
+
+ // Check the key bytes.
+ if (extractable) {
+ return crypto.subtle.exportKey('raw', clonedKey).then(function(result) {
+ bytesShouldMatchHexString("cloned key data", keyData, result);
+ });
+ }
+ });
+}
+
+for (var algorithmIndex = 0; algorithmIndex < kPossibleAlgorithms.length; ++algorithmIndex) {
jsbell 2014/03/13 20:16:07 Might be more readable to write these using forEac
eroman 2014/03/14 05:24:33 Done. You were right, much more readable with forE
+ for (var extractableIndex = 0; extractableIndex < kPossibleExtractable.length; ++extractableIndex) {
+ for (var usagesIndex = 0; usagesIndex < kPossibleKeyUsages.length; ++usagesIndex) {
+ for (var dataIndex = 0; dataIndex < kPossibleKeyData.length; ++dataIndex) {
+ var algorithmName = kPossibleAlgorithms[algorithmIndex];
+ var extractable = kPossibleExtractable[extractableIndex];
+ var keyUsages = kPossibleKeyUsages[usagesIndex];
+ var keyData = kPossibleKeyData[dataIndex];
+
+ addTask(runTest(algorithmName, extractable, keyUsages, keyData));
+ }
+ }
+ }
+}
+
+completeTestWhenAllTasksDone();
+
+</script>
+
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/crypto/clone-aesKey-expected.txt » ('j') | LayoutTests/crypto/resources/common.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698