GeezerVison is showing github.com — crypto: handle more webcrypto errors with OperationError · nodejs/node@1ba1809
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/aes.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,7 +124,7 @@ function asyncAesCtrCipher(mode, key, data, { counter, length }) { | 124 | 124 | 'OperationError'); | 125 | 125 | } | 126 | 126 |
| 127 | | - return jobPromise(new AESCipherJob( | | 127 | + return jobPromise(() => new AESCipherJob( | 128 | 128 | kCryptoJobAsync, | 129 | 129 | mode, | 130 | 130 | key[kKeyObject][kHandle], | @@ -137,7 +137,7 @@ function asyncAesCtrCipher(mode, key, data, { counter, length }) { | 137 | 137 | function asyncAesCbcCipher(mode, key, data, { iv }) { | 138 | 138 | iv = getArrayBufferOrView(iv, 'algorithm.iv'); | 139 | 139 | validateByteLength(iv, 'algorithm.iv', 16); | 140 | | - return jobPromise(new AESCipherJob( | | 140 | + return jobPromise(() => new AESCipherJob( | 141 | 141 | kCryptoJobAsync, | 142 | 142 | mode, | 143 | 143 | key[kKeyObject][kHandle], | @@ -147,7 +147,7 @@ function asyncAesCbcCipher(mode, key, data, { iv }) { | 147 | 147 | } | 148 | 148 |
| 149 | 149 | function asyncAesKwCipher(mode, key, data) { | 150 | | - return jobPromise(new AESCipherJob( | | 150 | + return jobPromise(() => new AESCipherJob( | 151 | 151 | kCryptoJobAsync, | 152 | 152 | mode, | 153 | 153 | key[kKeyObject][kHandle], | @@ -201,7 +201,7 @@ function asyncAesGcmCipher( | 201 | 201 | break; | 202 | 202 | } | 203 | 203 |
| 204 | | - return jobPromise(new AESCipherJob( | | 204 | + return jobPromise(() => new AESCipherJob( | 205 | 205 | kCryptoJobAsync, | 206 | 206 | mode, | 207 | 207 | key[kKeyObject][kHandle], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/cfrg.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -193,7 +193,7 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) { | 193 | 193 |
| 194 | 194 | function cfrgExportKey(key, format) { | 195 | 195 | emitExperimentalWarning(`The ${key.algorithm.name} Web Crypto API algorithm`); | 196 | | - return jobPromise(new ECKeyExportJob( | | 196 | + return jobPromise(() => new ECKeyExportJob( | 197 | 197 | kCryptoJobAsync, | 198 | 198 | format, | 199 | 199 | key[kKeyObject][kHandle])); | @@ -322,7 +322,7 @@ function eddsaSignVerify(key, data, { name, context }, signature) { | 322 | 322 | } | 323 | 323 | } | 324 | 324 |
| 325 | | - return jobPromise(new SignJob( | | 325 | + return jobPromise(() => new SignJob( | 326 | 326 | kCryptoJobAsync, | 327 | 327 | mode, | 328 | 328 | key[kKeyObject][kHandle], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/diffiehellman.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -357,7 +357,7 @@ async function ecdhDeriveBits(algorithm, baseKey, length) { | 357 | 357 | throw lazyDOMException('Named curve mismatch', 'InvalidAccessError'); | 358 | 358 | } | 359 | 359 |
| 360 | | - const bits = await jobPromise(new ECDHBitsJob( | | 360 | + const bits = await jobPromise(() => new ECDHBitsJob( | 361 | 361 | kCryptoJobAsync, | 362 | 362 | key.algorithm.name === 'ECDH' ? baseKey.algorithm.namedCurve : baseKey.algorithm.name, | 363 | 363 | key[kKeyObject][kHandle], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/ec.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,7 +150,7 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { | 150 | 150 | } | 151 | 151 |
| 152 | 152 | function ecExportKey(key, format) { | 153 | | - return jobPromise(new ECKeyExportJob( | | 153 | + return jobPromise(() => new ECKeyExportJob( | 154 | 154 | kCryptoJobAsync, | 155 | 155 | format, | 156 | 156 | key[kKeyObject][kHandle])); | @@ -285,7 +285,7 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) { | 285 | 285 | throw new ERR_MISSING_OPTION('algorithm.hash'); | 286 | 286 | const hashname = normalizeHashName(hash.name); | 287 | 287 |
| 288 | | - return jobPromise(new SignJob( | | 288 | + return jobPromise(() => new SignJob( | 289 | 289 | kCryptoJobAsync, | 290 | 290 | mode, | 291 | 291 | key[kKeyObject][kHandle], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,7 +183,7 @@ async function asyncDigest(algorithm, data) { | 183 | 183 | case 'SHA-384': | 184 | 184 | // Fall through | 185 | 185 | case 'SHA-512': | 186 | | - return jobPromise(new HashJob( | | 186 | + return jobPromise(() => new HashJob( | 187 | 187 | kCryptoJobAsync, | 188 | 188 | normalizeHashName(algorithm.name), | 189 | 189 | data, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/mac.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,7 +183,7 @@ async function hmacImportKey( | 183 | 183 |
| 184 | 184 | function hmacSignVerify(key, data, algorithm, signature) { | 185 | 185 | const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify; | 186 | | - return jobPromise(new HmacJob( | | 186 | + return jobPromise(() => new HmacJob( | 187 | 187 | kCryptoJobAsync, | 188 | 188 | mode, | 189 | 189 | normalizeHashName(key.algorithm.hash.name), | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/rsa.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ function rsaOaepCipher(mode, key, data, { label }) { | 116 | 116 | validateMaxBufferLength(label, 'algorithm.label'); | 117 | 117 | } | 118 | 118 |
| 119 | | - return jobPromise(new RSACipherJob( | | 119 | + return jobPromise(() => new RSACipherJob( | 120 | 120 | kCryptoJobAsync, | 121 | 121 | mode, | 122 | 122 | key[kKeyObject][kHandle], | @@ -223,7 +223,7 @@ async function rsaKeyGenerate( | 223 | 223 | } | 224 | 224 |
| 225 | 225 | function rsaExportKey(key, format) { | 226 | | - return jobPromise(new RSAKeyExportJob( | | 226 | + return jobPromise(() => new RSAKeyExportJob( | 227 | 227 | kCryptoJobAsync, | 228 | 228 | format, | 229 | 229 | key[kKeyObject][kHandle], | @@ -346,7 +346,7 @@ function rsaSignVerify(key, data, { saltLength }, signature) { | 346 | 346 | if (key.type !== type) | 347 | 347 | throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError'); | 348 | 348 |
| 349 | | - return jobPromise(new SignJob( | | 349 | + return jobPromise(() => new SignJob( | 350 | 350 | kCryptoJobAsync, | 351 | 351 | signature === undefined ? kSignJobModeSign : kSignJobModeVerify, | 352 | 352 | key[kKeyObject][kHandle], | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -286,10 +286,15 @@ function onDone(resolve, reject, err, result) { | 286 | 286 | resolve(result); | 287 | 287 | } | 288 | 288 |
| 289 | | -function jobPromise(job) { | | 289 | +function jobPromise(getJob) { | 290 | 290 | return new Promise((resolve, reject) => { | 291 | | - job.ondone = FunctionPrototypeBind(onDone, job, resolve, reject); | 292 | | - job.run(); | | 291 | + try { | | 292 | + const job = getJob(); | | 293 | + job.ondone = FunctionPrototypeBind(onDone, job, resolve, reject); | | 294 | + job.run(); | | 295 | + } catch (err) { | | 296 | + onDone(resolve, reject, err); | | 297 | + } | 293 | 298 | }); | 294 | 299 | } | 295 | 300 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-digest.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,7 +83,7 @@ Promise.all([1, [], {}, null, undefined].map((i) => | 83 | 83 | // addition to the API, and is added as a support for future additional | 84 | 84 | // hash algorithms that support variable digest output lengths. | 85 | 85 | assert.rejects(subtle.digest({ name: 'SHA-512', length: 510 }, kData), { | 86 | | - message: /Digest method not supported/ | | 86 | + name: 'OperationError', | 87 | 87 | }).then(common.mustCall()); | 88 | 88 |
| 89 | 89 | const kSourceData = { | |
|