MCPcopy Create free account
hub / github.com/nodejs/node / allAlgorithmSpecifiersFor

Function allAlgorithmSpecifiersFor

test/fixtures/wpt/WebCryptoAPI/util/helpers.js:179–228  ·  view source on GitHub ↗
(algorithmName)

Source from the content-addressed store, hash-verified

177// The algorithm parameter is an object with a name and other
178// properties. Given the name, generate all valid parameters.
179function allAlgorithmSpecifiersFor(algorithmName) {
180 var results = [];
181
182 // RSA key generation is slow. Test a minimal set of parameters
183 var hashes = ["SHA-1", "SHA-256"];
184
185 // EC key generation is a lot faster. Check all curves in the spec
186 var curves = ["P-256", "P-384", "P-521"];
187
188 if (algorithmName.toUpperCase().substring(0, 3) === "AES") {
189 // Specifier properties are name and length
190 [128, 192, 256].forEach(function(length) {
191 results.push({name: algorithmName, length: length});
192 });
193 } else if (algorithmName.toUpperCase() === "HMAC") {
194 [
195 {hash: "SHA-1", length: 160},
196 {hash: "SHA-256", length: 256},
197 {hash: "SHA-384", length: 384},
198 {hash: "SHA-512", length: 512},
199 {hash: "SHA-1"},
200 {hash: "SHA-256"},
201 {hash: "SHA-384"},
202 {hash: "SHA-512"},
203 ].forEach(function(hashAlgorithm) {
204 results.push({name: algorithmName, ...hashAlgorithm});
205 });
206 } else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {
207 hashes.forEach(function(hashName) {
208 results.push({name: algorithmName, hash: hashName, modulusLength: 2048, publicExponent: new Uint8Array([1,0,1])});
209 });
210 } else if (algorithmName.toUpperCase().substring(0, 2) === "EC") {
211 curves.forEach(function(curveName) {
212 results.push({name: algorithmName, namedCurve: curveName});
213 });
214 } else if (algorithmName.toUpperCase().startsWith("KMAC")) {
215 [
216 {length: 128},
217 {length: 160},
218 {length: 256},
219 ].forEach(function(hashAlgorithm) {
220 results.push({name: algorithmName, ...hashAlgorithm});
221 });
222 } else {
223 results.push(algorithmName);
224 results.push({ name: algorithmName });
225 }
226
227 return results;
228}
229
230
231// Create every possible valid usages parameter, given legal

Callers 4

run_testFunction · 0.85
run_testFunction · 0.85
run_testFunction · 0.85
run_testFunction · 0.85

Calls 2

forEachMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected