(algorithm, invalidLengthMessage, allowZeroKey = false)
| 130 | } |
| 131 | |
| 132 | function 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 | |
| 166 | function hmacVectors() { |
| 167 | const vectors = []; |
no test coverage detected