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

Function getKeyLength

lib/internal/crypto/webcrypto.js:299–336  ·  view source on GitHub ↗
({ name, length, hash })

Source from the content-addressed store, hash-verified

297}
298
299function getKeyLength({ name, length, hash }) {
300 switch (name) {
301 case 'AES-CTR':
302 case 'AES-CBC':
303 case 'AES-GCM':
304 case 'AES-OCB':
305 case 'AES-KW':
306 if (length !== 128 && length !== 192 && length !== 256)
307 throw lazyDOMException('Invalid key length', 'OperationError');
308
309 return length;
310 case 'HMAC':
311 if (length === undefined) {
312 return getBlockSize(hash?.name);
313 }
314
315 if (typeof length === 'number' && length !== 0) {
316 return length;
317 }
318
319 throw lazyDOMException('Invalid key length', 'OperationError');
320 case 'KMAC128':
321 case 'KMAC256':
322 if (typeof length === 'number') {
323 return length;
324 }
325
326 return name === 'KMAC128' ? 128 : 256;
327 case 'HKDF':
328 case 'PBKDF2':
329 case 'Argon2d':
330 case 'Argon2i':
331 case 'Argon2id':
332 return null;
333 case 'ChaCha20-Poly1305':
334 return 256;
335 }
336}
337
338function deriveKey(
339 algorithm,

Callers 2

deriveKeyImplFunction · 0.85
supportsMethod · 0.85

Calls 2

lazyDOMExceptionFunction · 0.85
getBlockSizeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…