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

Side by Side Diff: LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js

Issue 958353003: [WebCrypto] Move cloneKey test to respective algorithm directory (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 if (self.importScripts) {
2 <html> 2 importScripts('common.js');
3 <head> 3 }
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 4
11 <script> 5 function runCloneSymmetricTests(algorithmName, extractable, keyUsages, keyData, hashName, keyHasLength)
12 description("Tests structured cloning of AES keys");
13
14 jsTestIsAsync = true;
15
16 // Tests the 32 permutations of keys generated by:
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData
18 //
19 // For practical reasons these tests are not exhaustive.
20
21 var k128BitData = "30112233445566778899aabbccddeeff"
22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0 e0f";
23
24 var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM'];
25 var kPossibleExtractable = [true, false];
26 var kPossibleKeyUsages = [['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrap Key', 'unwrapKey']];
27 var kPossibleKeyData = [k128BitData, k256BitData];
28
29 function runTest(algorithmName, extractable, keyUsages, keyData)
30 { 6 {
31 var importData = hexStringToUint8Array(keyData); 7 var importData = hexStringToUint8Array(keyData);
32 var importAlgorithm = { name: algorithmName }; 8 var importAlgorithm = { name: algorithmName };
9 if (hashName)
10 importAlgorithm.hash = { name: hashName };
11 var expectingHash = (algorithmName.toLowerCase() === "hmac");
33 12
34 var results = {}; 13 var results = {};
35 14
36 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) { 15 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) {
37 results.importedKey = importedKey; 16 results.importedKey = importedKey;
38 importedKey.extraProperty = 'hi'; 17 importedKey.extraProperty = 'hi';
39 return cloneKey(importedKey); 18 return cloneKey(importedKey);
40 }).then(function(clonedKey) { 19 }).then(function(clonedKey) {
41 results.clonedKey = clonedKey; 20 results.clonedKey = clonedKey;
42 if (extractable) 21 if (extractable)
43 return crypto.subtle.exportKey('raw', clonedKey); 22 return crypto.subtle.exportKey('raw', clonedKey);
44 return null; 23 return null;
45 }).then(function(clonedKeyData) { 24 }).then(function(clonedKeyData) {
46 importedKey = results.importedKey; 25 importedKey = results.importedKey;
47 clonedKey = results.clonedKey; 26 clonedKey = results.clonedKey;
48 27
49 shouldEvaluateAs("importedKey.extraProperty", "hi"); 28 shouldEvaluateAs("importedKey.extraProperty", "hi");
50 shouldEvaluateAs("importedKey.type", "secret"); 29 shouldEvaluateAs("importedKey.type", "secret");
51 shouldEvaluateAs("importedKey.extractable", extractable); 30 shouldEvaluateAs("importedKey.extractable", extractable);
52 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); 31 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
53 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8); 32 if (keyHasLength)
33 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8);
34 if (expectingHash)
35 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
54 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); 36 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
55 37
56 shouldNotBe("importedKey", "clonedKey"); 38 shouldNotBe("importedKey", "clonedKey");
57 39
58 shouldBeUndefined("clonedKey.extraProperty"); 40 shouldBeUndefined("clonedKey.extraProperty");
59 shouldEvaluateAs("clonedKey.type", "secret"); 41 shouldEvaluateAs("clonedKey.type", "secret");
60 shouldEvaluateAs("clonedKey.extractable", extractable); 42 shouldEvaluateAs("clonedKey.extractable", extractable);
61 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); 43 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
62 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8); 44 if (keyHasLength)
45 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8 );
46 if (expectingHash)
47 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
63 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); 48 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
64 49
65 logSerializedKey(importedKey); 50 logSerializedKey(importedKey);
66 51
67 if (extractable) 52 if (extractable)
68 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData); 53 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData);
69 54
70 debug(""); 55 debug("");
71 }); 56 });
72 } 57 }
73 58
74 var lastPromise = Promise.resolve(null); 59 function testCloneSymmetricKeys(algorithmName, possibleHashAlgorithms, possibleE xtractable, possibleKeyUsages, possibleKeyData, keyHasLength)
60 {
61 var lastPromise = Promise.resolve(null);
75 62
76 kPossibleAlgorithms.forEach(function(algorithmName) { 63 possibleHashAlgorithms.forEach(function(hashName) {
77 kPossibleExtractable.forEach(function(extractable) { 64 possibleExtractable.forEach(function(extractable) {
78 kPossibleKeyUsages.forEach(function(keyUsages) { 65 possibleKeyUsages.forEach(function(keyUsages) {
79 kPossibleKeyData.forEach(function(keyData) { 66 possibleKeyData.forEach(function(keyData) {
80 lastPromise = lastPromise.then(runTest.bind(null, algorithmName, extractable, keyUsages, keyData)); 67 lastPromise = lastPromise.then(runCloneSymmetricTests.bind(n ull, algorithmName, extractable, keyUsages, keyData, hashName, keyHasLength));
68 });
81 }); 69 });
82 }); 70 });
83 }); 71 });
84 });
85 72
86 lastPromise.then(finishJSTest, failAndFinishJSTest); 73 return lastPromise;
87 74 }
88 </script>
89
90 </body>
91 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/subtle/resources/rsa-cloneKey.js ('k') | LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5/cloneKey.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698