| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,7 +142,6 @@ function hkdfSync(hash, key, salt, info, length) { | |||
| 142 | 142 | } | |
| 143 | 143 | ||
| 144 | 144 | async function hkdfDeriveBits(algorithm, baseKey, length) { | |
| 145 | - validateUint32(length, 'length'); | ||
| 146 | 145 | const { hash } = algorithm; | |
| 147 | 146 | const salt = getArrayBufferOrView(algorithm.salt, 'algorithm.salt'); | |
| 148 | 147 | const info = getArrayBufferOrView(algorithm.info, 'algorithm.info'); | |
@@ -153,6 +152,9 @@ async function hkdfDeriveBits(algorithm, baseKey, length) { | |||
| 153 | 152 | if (length !== undefined) { | |
| 154 | 153 | if (length === 0) | |
| 155 | 154 | throw lazyDOMException('length cannot be zero', 'OperationError'); | |
| 155 | + if (length === null) | ||
| 156 | + throw lazyDOMException('length cannot be null', 'OperationError'); | ||
| 157 | + validateUint32(length, 'length'); | ||
| 156 | 158 | if (length % 8) { | |
| 157 | 159 | throw lazyDOMException( | |
| 158 | 160 | 'length must be a multiple of 8', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,13 +98,16 @@ function check(password, salt, iterations, keylen, digest) { | |||
| 98 | 98 | } | |
| 99 | 99 | ||
| 100 | 100 | async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |
| 101 | - validateUint32(length, 'length'); | ||
| 102 | 101 | const { iterations } = algorithm; | |
| 103 | 102 | let { hash } = algorithm; | |
| 104 | 103 | const salt = getArrayBufferOrView(algorithm.salt, 'algorithm.salt'); | |
| 105 | 104 | if (hash === undefined) | |
| 106 | 105 | throw new ERR_MISSING_OPTION('algorithm.hash'); | |
| 107 | - validateInteger(iterations, 'algorithm.iterations', 1); | ||
| 106 | + validateInteger(iterations, 'algorithm.iterations'); | ||
| 107 | + if (iterations === 0) | ||
| 108 | + throw lazyDOMException( | ||
| 109 | + 'iterations cannot be zero', | ||
| 110 | + 'OperationError'); | ||
| 108 | 111 | ||
| 109 | 112 | hash = normalizeHashName(hash.name); | |
| 110 | 113 | ||
@@ -114,6 +117,9 @@ async function pbkdf2DeriveBits(algorithm, baseKey, length) { | |||
| 114 | 117 | if (length !== undefined) { | |
| 115 | 118 | if (length === 0) | |
| 116 | 119 | throw lazyDOMException('length cannot be zero', 'OperationError'); | |
| 120 | + if (length === null) | ||
| 121 | + throw lazyDOMException('length cannot be null', 'OperationError'); | ||
| 122 | + validateUint32(length, 'length'); | ||
| 117 | 123 | if (length % 8) { | |
| 118 | 124 | throw lazyDOMException( | |
| 119 | 125 | 'length must be a multiple of 8', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -259,15 +259,18 @@ async function testDeriveBitsBadLengths( | |||
| 259 | 259 | return Promise.all([ | |
| 260 | 260 | assert.rejects( | |
| 261 | 261 | subtle.deriveBits(algorithm, baseKeys[size], 0), { | |
| 262 | - message: /length cannot be zero/ | ||
| 262 | + message: /length cannot be zero/, | ||
| 263 | + name: 'OperationError', | ||
| 263 | 264 | }), | |
| 264 | 265 | assert.rejects( | |
| 265 | 266 | subtle.deriveBits(algorithm, baseKeys[size], null), { | |
| 266 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 267 | + message: 'length cannot be null', | ||
| 268 | + name: 'OperationError', | ||
| 267 | 269 | }), | |
| 268 | 270 | assert.rejects( | |
| 269 | 271 | subtle.deriveBits(algorithm, baseKeys[size], 15), { | |
| 270 | - message: /length must be a multiple of 8/ | ||
| 272 | + message: /length must be a multiple of 8/, | ||
| 273 | + name: 'OperationError', | ||
| 271 | 274 | }), | |
| 272 | 275 | ]); | |
| 273 | 276 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -448,15 +448,18 @@ async function testDeriveBitsBadLengths( | |||
| 448 | 448 | return Promise.all([ | |
| 449 | 449 | assert.rejects( | |
| 450 | 450 | subtle.deriveBits(algorithm, baseKeys[size], 0), { | |
| 451 | - message: /length cannot be zero/ | ||
| 451 | + message: /length cannot be zero/, | ||
| 452 | + name: 'OperationError', | ||
| 452 | 453 | }), | |
| 453 | 454 | assert.rejects( | |
| 454 | 455 | subtle.deriveBits(algorithm, baseKeys[size], null), { | |
| 455 | - code: 'ERR_INVALID_ARG_TYPE' | ||
| 456 | + message: 'length cannot be null', | ||
| 457 | + name: 'OperationError', | ||
| 456 | 458 | }), | |
| 457 | 459 | assert.rejects( | |
| 458 | 460 | subtle.deriveBits(algorithm, baseKeys[size], 15), { | |
| 459 | - message: /length must be a multiple of 8/ | ||
| 461 | + message: /length must be a multiple of 8/, | ||
| 462 | + name: 'OperationError', | ||
| 460 | 463 | }), | |
| 461 | 464 | ]); | |
| 462 | 465 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments