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

Function macInvalid

test/parallel/test-crypto-key-objects-to-crypto-key.js:132–164  ·  view source on GitHub ↗
(algorithm, invalidLengthMessage, allowZeroKey = false)

Source from the content-addressed store, hash-verified

130}
131
132function macInvalid(algorithm, invalidLengthMessage, allowZeroKey = false) {
133 const key = createSecretKey(randomBytes(32));
134 const usages = ['sign', 'verify'];
135
136 if (allowZeroKey) {
137 const zeroKey = createSecretKey(Buffer.alloc(0))
138 .toCryptoKey(algorithm, true, usages);
139 assert.strictEqual(zeroKey.algorithm.length, 0);
140
141 const explicitZeroKey = createSecretKey(Buffer.alloc(0))
142 .toCryptoKey({ ...algorithm, length: 0 }, true, usages);
143 assert.strictEqual(explicitZeroKey.algorithm.length, 0);
144 } else {
145 assert.throws(() => {
146 createSecretKey(Buffer.alloc(0)).toCryptoKey(algorithm, true, usages);
147 }, {
148 name: 'DataError',
149 message: 'Zero-length key is not supported',
150 });
151 }
152
153 assert.throws(() => key.toCryptoKey(algorithm, true, []), {
154 name: 'SyntaxError',
155 message: 'Usages cannot be empty when importing a secret key.'
156 });
157
158 assert.throws(() => {
159 key.toCryptoKey({ ...algorithm, length: 0 }, true, usages);
160 }, {
161 name: 'DataError',
162 message: invalidLengthMessage,
163 });
164}
165
166function hmacVectors() {
167 const vectors = [];

Calls 4

createSecretKeyFunction · 0.85
randomBytesFunction · 0.85
toCryptoKeyMethod · 0.80
allocMethod · 0.80

Tested by

no test coverage detected