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

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: Update serialized-script-value.html for version bump 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') | no next file with comments »
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..4f6d390a7303651d357c60915d2edcf3f45e09d3
--- /dev/null
+++ b/LayoutTests/crypto/clone-aesKey.html
@@ -0,0 +1,92 @@
+<!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 importData = hexStringToUint8Array(keyData);
+ var importAlgorithm = { name: algorithmName };
+
+ var results = {};
+
+ return crypto.subtle.importKey('raw', importData, importAlgorithm, extractable, keyUsages).then(function(importedKey) {
+ results.importedKey = importedKey;
+ importedKey.extraProperty = 'hi';
+ return cloneKey(importedKey);
+ }).then(function(clonedKey) {
+ results.clonedKey = clonedKey;
+ if (extractable)
+ return crypto.subtle.exportKey('raw', clonedKey);
+ return null;
+ }).then(function(clonedKeyData) {
+ importedKey = results.importedKey;
+ clonedKey = results.clonedKey;
+
+ shouldEvaluateAs("importedKey.extraProperty", "hi");
+ shouldEvaluateAs("importedKey.type", "secret");
+ shouldEvaluateAs("importedKey.extractable", extractable);
+ shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
+ shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8);
+ shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
+
+ shouldBeTrue("importedKey != clonedKey");
+
+ shouldBeUndefined("clonedKey.extraProperty");
+ shouldEvaluateAs("clonedKey.type", "secret");
+ shouldEvaluateAs("clonedKey.extractable", extractable);
+ shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
+ shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8);
+ shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
+
+ logSerializedKey(importedKey);
+
+ if (extractable)
+ bytesShouldMatchHexString("Cloned key exported data", keyData, clonedKeyData);
+
+ debug("");
+ });
+}
+
+var lastPromise = Promise.resolve(null);
+
+kPossibleAlgorithms.forEach(function(algorithmName) {
+ kPossibleExtractable.forEach(function(extractable) {
+ kPossibleKeyUsages.forEach(function(keyUsages) {
+ kPossibleKeyData.forEach(function(keyData) {
+ lastPromise = lastPromise.then(runTest.bind(null, algorithmName, extractable, keyUsages, keyData));
+ });
+ });
+ });
+});
+
+lastPromise.then(finishJSTest, failAndFinishJSTest);
+
+</script>
+
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/crypto/clone-aesKey-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698