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

Function normalizeKeyLength

lib/internal/crypto/mac.js:45–64  ·  view source on GitHub ↗
(handle, algorithm)

Source from the content-addressed store, hash-verified

43const kUsages = ['sign', 'verify'];
44
45function normalizeKeyLength(handle, algorithm) {
46 let length = handle.getSymmetricKeySize() * 8;
47 if (length === 0 && algorithm.name === 'HMAC')
48 throw lazyDOMException('Zero-length key is not supported', 'DataError');
49
50 if (algorithm.length !== undefined) {
51 const byteLength = numBitsToBytes(algorithm.length);
52 if (byteLength !== handle.getSymmetricKeySize())
53 throw lazyDOMException('Invalid key length', 'DataError');
54
55 if (algorithm.length % 8 !== 0) {
56 handle = importSecretKey(
57 truncateToBitLength(algorithm.length, handle.export()));
58 }
59
60 length = algorithm.length;
61 }
62
63 return { handle, length };
64}
65
66function hmacGenerateKey(algorithm, extractable, usages) {
67 const {

Callers 1

macImportKeyFunction · 0.85

Calls 5

lazyDOMExceptionFunction · 0.85
numBitsToBytesFunction · 0.85
importSecretKeyFunction · 0.85
truncateToBitLengthFunction · 0.85
exportMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…