Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / resources / rsa-cloneKey.js
blob889b0a96cd3aaa7aef7e5ce84f6a39d44158850d
1 if (self.importScripts) {
2 importScripts('common.js');
5 function runCloneRSATests(format, algorithmName, hashName, keyType, extractable, keyUsages, keyData)
7 var importData = hexStringToUint8Array(keyData[format]);
8 var importAlgorithm = { name: algorithmName, hash: { name: hashName } };
10 var results = {};
12 return crypto.subtle.importKey(format, importData, importAlgorithm, extractable, keyUsages).then(function(importedKey) {
13 results.importedKey = importedKey;
14 importedKey.extraProperty = 'hi';
15 return cloneKey(importedKey);
16 }).then(function(clonedKey) {
17 results.clonedKey = clonedKey;
18 if (extractable)
19 return crypto.subtle.exportKey(format, clonedKey);
20 return null;
21 }).then(function(clonedKeyData) {
22 importedKey = results.importedKey;
23 clonedKey = results.clonedKey;
25 shouldEvaluateAs("importedKey.extraProperty", "hi");
26 shouldEvaluateAs("importedKey.type", keyType);
27 shouldEvaluateAs("importedKey.extractable", extractable);
28 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
29 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusLengthBits);
30 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyData.publicExponent, importedKey.algorithm.publicExponent);
31 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
32 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
34 shouldNotBe("importedKey", "clonedKey");
36 shouldBeUndefined("clonedKey.extraProperty");
37 shouldEvaluateAs("clonedKey.type", keyType);
38 shouldEvaluateAs("clonedKey.extractable", extractable);
39 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
40 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLengthBits);
41 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.publicExponent, clonedKey.algorithm.publicExponent);
42 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
43 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
45 logSerializedKey(importedKey);
47 if (extractable)
48 bytesShouldMatchHexString("Cloned key exported data", keyData[format], clonedKeyData);
50 debug("");
51 });
54 function testCloneRSAKeys(format, algorithmName, possibleKeyUsages, keyType, possibleKeyData)
56 var lastPromise = Promise.resolve(null);
57 var kPossibleExtractable = [true, false];
58 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
60 kPossibleHashAlgorithms.forEach(function(hashName) {
61 kPossibleExtractable.forEach(function(extractable) {
62 possibleKeyUsages.forEach(function(keyUsages) {
63 possibleKeyData.forEach(function(keyData) {
64 lastPromise = lastPromise.then(runCloneRSATests.bind(null, format, algorithmName, hashName, keyType, extractable, keyUsages, keyData));
65 });
66 });
67 });
68 });
70 return lastPromise;
73 function testCloneRSAPublicKeys(algorithmName, possibleKeyUsages, keyData)
75 return testCloneRSAKeys("spki", algorithmName, possibleKeyUsages, "public", keyData);
78 function testCloneRSAPrivateKeys(algorithmName, possibleKeyUsages, keyData)
80 return testCloneRSAKeys("pkcs8", algorithmName, possibleKeyUsages, "private", keyData);