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

Side by Side Diff: LayoutTests/crypto/subtle/resources/rsa-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 <script src="resources/keys.js"></script>
7 </head>
8 <body>
9 <p id="description"></p>
10 <div id="console"></div>
11 4
12 <script> 5 function runCloneRSATests(format, algorithmName, hashName, keyType, extractable, keyUsages, keyData)
13 description("Tests structured cloning of RSA public keys (with a hash)");
14
15 jsTestIsAsync = true;
16
17 // Tests the 12 permutations of keys generated by:
18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData x kPossibleHashAlgorithms
19 //
20 // For practical reasons these tests are not exhaustive.
21
22 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5'];
23 var kPossibleExtractable = [true, false];
24 var kPossibleKeyUsages = [[], ['verify']];
25 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
26
27 var kPossibleKeyData = [
28 kKeyData.rsa2,
29 kKeyData.rsa3
30 ];
31
32 function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
33 { 6 {
34 var importData = hexStringToUint8Array(keyData.spki); 7 var importData = hexStringToUint8Array(keyData[format]);
35 var importAlgorithm = { name: algorithmName, hash: {name: hashName} }; 8 var importAlgorithm = { name: algorithmName, hash: { name: hashName } };
eroman 2015/03/05 19:58:50 nit: remove extra space on the left. The other ext
36 9
37 var results = {}; 10 var results = {};
38 11
39 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) { 12 return crypto.subtle.importKey(format, importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) {
eroman 2015/03/05 19:58:50 Good generalization!
40 results.importedKey = importedKey; 13 results.importedKey = importedKey;
41 importedKey.extraProperty = 'hi'; 14 importedKey.extraProperty = 'hi';
42 return cloneKey(importedKey); 15 return cloneKey(importedKey);
43 }).then(function(clonedKey) { 16 }).then(function(clonedKey) {
44 results.clonedKey = clonedKey; 17 results.clonedKey = clonedKey;
45 if (extractable) 18 if (extractable)
46 return crypto.subtle.exportKey('spki', clonedKey); 19 return crypto.subtle.exportKey(format, clonedKey);
47 return null; 20 return null;
48 }).then(function(clonedKeyData) { 21 }).then(function(clonedKeyData) {
49 importedKey = results.importedKey; 22 importedKey = results.importedKey;
50 clonedKey = results.clonedKey; 23 clonedKey = results.clonedKey;
51 24
52 shouldEvaluateAs("importedKey.extraProperty", "hi"); 25 shouldEvaluateAs("importedKey.extraProperty", "hi");
53 shouldEvaluateAs("importedKey.type", "public"); 26 shouldEvaluateAs("importedKey.type", keyType);
54 shouldEvaluateAs("importedKey.extractable", extractable); 27 shouldEvaluateAs("importedKey.extractable", extractable);
55 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); 28 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
56 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits); 29 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits);
57 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent); 30 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent);
58 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName); 31 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); 32 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
60 33
61 shouldNotBe("importedKey", "clonedKey"); 34 shouldNotBe("importedKey", "clonedKey");
62 35
63 shouldBeUndefined("clonedKey.extraProperty"); 36 shouldBeUndefined("clonedKey.extraProperty");
64 shouldEvaluateAs("clonedKey.type", "public"); 37 shouldEvaluateAs("clonedKey.type", keyType);
65 shouldEvaluateAs("clonedKey.extractable", extractable); 38 shouldEvaluateAs("clonedKey.extractable", extractable);
66 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); 39 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
67 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen gthBits); 40 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen gthBits);
68 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent); 41 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent);
69 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName); 42 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
70 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); 43 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
71 44
72 logSerializedKey(importedKey); 45 logSerializedKey(importedKey);
73 46
74 if (extractable) 47 if (extractable)
75 bytesShouldMatchHexString("Cloned key exported data", keyData.spki, clonedKeyData); 48 bytesShouldMatchHexString("Cloned key exported data", keyData[format ], clonedKeyData);
76 49
77 debug(""); 50 debug("");
78 }); 51 });
79 } 52 }
80 53
81 var lastPromise = Promise.resolve(null); 54 function testCloneRSAKeys(format, algorithmName, possibleKeyUsages, keyType, pos sibleKeyData)
55 {
56 var lastPromise = Promise.resolve(null);
57 var kPossibleExtractable = [true, false];
58 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
82 59
83 kPossibleAlgorithms.forEach(function(algorithmName) { 60 kPossibleHashAlgorithms.forEach(function(hashName) {
84 kPossibleExtractable.forEach(function(extractable) { 61 kPossibleExtractable.forEach(function(extractable) {
85 kPossibleKeyUsages.forEach(function(keyUsages) { 62 possibleKeyUsages.forEach(function(keyUsages) {
86 kPossibleKeyData.forEach(function(keyData) { 63 possibleKeyData.forEach(function(keyData) {
87 kPossibleHashAlgorithms.forEach(function(hashName) { 64 lastPromise = lastPromise.then(runCloneRSATests.bind(null, f ormat, algorithmName, hashName, keyType, extractable, keyUsages, keyData));
88 lastPromise = lastPromise.then(runTest.bind(null, algorithmN ame, hashName, extractable, keyUsages, keyData));
89 }); 65 });
90 }); 66 });
91 }); 67 });
92 }); 68 });
93 });
94 69
95 lastPromise.then(finishJSTest, failAndFinishJSTest); 70 return lastPromise;
71 }
96 72
97 </script> 73 function testCloneRSAPublicKeys(algorithmName, possibleKeyUsages, keyData)
74 {
75 return testCloneRSAKeys("spki", algorithmName, possibleKeyUsages, "public", keyData);
76 }
98 77
99 </body> 78 function testCloneRSAPrivateKeys(algorithmName, possibleKeyUsages, keyData)
100 </html> 79 {
80 return testCloneRSAKeys("pkcs8", algorithmName, possibleKeyUsages, "private" , keyData);
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698