(algorithm, baseKey, length = null)
| 249 | } |
| 250 | |
| 251 | function deriveBitsImpl(algorithm, baseKey, length = null) { |
| 252 | const prefix = prepareSubtleMethod(this, 'deriveBits', arguments.length, 2); |
| 253 | let i = 0; |
| 254 | algorithm = convertSubtleArgument( |
| 255 | prefix, 'AlgorithmIdentifier', algorithm, i++); |
| 256 | baseKey = convertSubtleArgument(prefix, 'CryptoKey', baseKey, i++); |
| 257 | if (length !== null) { |
| 258 | length = convertSubtleArgument(prefix, 'unsigned long', length, i++); |
| 259 | } |
| 260 | |
| 261 | const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'deriveBits'); |
| 262 | if (!hasCryptoKeyUsage(baseKey, 'deriveBits')) { |
| 263 | throw lazyDOMException( |
| 264 | 'baseKey does not have deriveBits usage', |
| 265 | 'InvalidAccessError'); |
| 266 | } |
| 267 | if (getCryptoKeyAlgorithm(baseKey).name !== normalizedAlgorithm.name) |
| 268 | throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError'); |
| 269 | switch (normalizedAlgorithm.name) { |
| 270 | case 'X25519': |
| 271 | // Fall through |
| 272 | case 'X448': |
| 273 | // Fall through |
| 274 | case 'ECDH': |
| 275 | return require('internal/crypto/diffiehellman') |
| 276 | .ecdhDeriveBits(normalizedAlgorithm, baseKey, length); |
| 277 | case 'HKDF': |
| 278 | return require('internal/crypto/hkdf') |
| 279 | .hkdfDeriveBits(normalizedAlgorithm, baseKey, length); |
| 280 | case 'PBKDF2': |
| 281 | return require('internal/crypto/pbkdf2') |
| 282 | .pbkdf2DeriveBits(normalizedAlgorithm, baseKey, length); |
| 283 | case 'Argon2d': |
| 284 | // Fall through |
| 285 | case 'Argon2i': |
| 286 | // Fall through |
| 287 | case 'Argon2id': |
| 288 | return require('internal/crypto/argon2') |
| 289 | .argon2DeriveBits(normalizedAlgorithm, baseKey, length); |
| 290 | /* c8 ignore start */ |
| 291 | default: { |
| 292 | const assert = require('internal/assert'); |
| 293 | assert.fail('Unreachable code'); |
| 294 | } |
| 295 | /* c8 ignore stop */ |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | function getKeyLength({ name, length, hash }) { |
| 300 | switch (name) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…