MCPcopy Index your code
hub / github.com/nodejs/node / generateKeyImpl

Function generateKeyImpl

lib/internal/crypto/webcrypto.js:167–245  ·  view source on GitHub ↗
(
  algorithm,
  extractable,
  keyUsages)

Source from the content-addressed store, hash-verified

165}
166
167function generateKeyImpl(
168 algorithm,
169 extractable,
170 keyUsages) {
171 const prefix = prepareSubtleMethod(this, 'generateKey', arguments.length, 3);
172 let i = 0;
173 algorithm = convertSubtleArgument(
174 prefix, 'AlgorithmIdentifier', algorithm, i++);
175 extractable = convertSubtleArgument(prefix, 'boolean', extractable, i++);
176 const usages = convertSubtleArgument(
177 prefix, 'sequence<KeyUsage>', keyUsages, i++);
178
179 const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'generateKey');
180 switch (normalizedAlgorithm.name) {
181 case 'RSASSA-PKCS1-v1_5':
182 // Fall through
183 case 'RSA-PSS':
184 // Fall through
185 case 'RSA-OAEP':
186 return require('internal/crypto/rsa')
187 .rsaKeyGenerate(normalizedAlgorithm, extractable, usages);
188 case 'Ed25519':
189 // Fall through
190 case 'Ed448':
191 // Fall through
192 case 'X25519':
193 // Fall through
194 case 'X448':
195 return require('internal/crypto/cfrg')
196 .cfrgGenerateKey(normalizedAlgorithm, extractable, usages);
197 case 'ECDSA':
198 // Fall through
199 case 'ECDH':
200 return require('internal/crypto/ec')
201 .ecGenerateKey(normalizedAlgorithm, extractable, usages);
202 case 'HMAC':
203 return require('internal/crypto/mac')
204 .hmacGenerateKey(normalizedAlgorithm, extractable, usages);
205 case 'AES-CTR':
206 // Fall through
207 case 'AES-CBC':
208 // Fall through
209 case 'AES-GCM':
210 // Fall through
211 case 'AES-OCB':
212 // Fall through
213 case 'AES-KW':
214 return require('internal/crypto/aes')
215 .aesGenerateKey(normalizedAlgorithm, extractable, usages);
216 case 'ChaCha20-Poly1305':
217 return require('internal/crypto/chacha20_poly1305')
218 .c20pGenerateKey(normalizedAlgorithm, extractable, usages);
219 case 'ML-DSA-44':
220 // Fall through
221 case 'ML-DSA-65':
222 // Fall through
223 case 'ML-DSA-87':
224 return require('internal/crypto/ml_dsa')

Callers

nothing calls this directly

Calls 5

prepareSubtleMethodFunction · 0.85
convertSubtleArgumentFunction · 0.85
normalizeAlgorithmFunction · 0.70
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…