({ name, length, hash })
| 297 | } |
| 298 | |
| 299 | function 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 | |
| 338 | function deriveKey( |
| 339 | algorithm, |
no test coverage detected
searching dependent graphs…