GeezerVison is showing github.com — crypto: avoid calls to `promise.catch()` · nodejs/node@aed9fd5
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 +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -195,12 +195,15 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) { | 195 | 195 | 'SyntaxError'); | 196 | 196 | } | 197 | 197 |
| 198 | | - const key = await generateKey('aes', { length }).catch((err) => { | | 198 | + let key; | | 199 | + try { | | 200 | + key = await generateKey('aes', { length }); | | 201 | + } catch (err) { | 199 | 202 | throw lazyDOMException( | 200 | 203 | 'The operation failed for an operation-specific reason' + | 201 | 204 | `[${err.message}]`, | 202 | 205 | { name: 'OperationError', cause: err }); | 203 | | - }); | | 206 | + } | 204 | 207 |
| 205 | 208 | return new InternalCryptoKey( | 206 | 209 | key, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/cfrg.js +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -148,11 +148,14 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) { | 148 | 148 | break; | 149 | 149 | } | 150 | 150 |
| 151 | | - const keyPair = await generateKeyPair(genKeyType).catch((err) => { | | 151 | + let keyPair; | | 152 | + try { | | 153 | + keyPair = await generateKeyPair(genKeyType); | | 154 | + } catch (err) { | 152 | 155 | throw lazyDOMException( | 153 | 156 | 'The operation failed for an operation-specific reason', | 154 | 157 | { name: 'OperationError', cause: err }); | 155 | | - }); | | 158 | + } | 156 | 159 |
| 157 | 160 | let publicUsages; | 158 | 161 | let privateUsages; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/ec.js +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -96,11 +96,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { | 96 | 96 | // Fall through | 97 | 97 | } | 98 | 98 |
| 99 | | - const keypair = await generateKeyPair('ec', { namedCurve }).catch((err) => { | | 99 | + let keyPair; | | 100 | + try { | | 101 | + keyPair = await generateKeyPair('ec', { namedCurve }); | | 102 | + } catch(err) { | 100 | 103 | throw lazyDOMException( | 101 | 104 | 'The operation failed for an operation-specific reason', | 102 | 105 | { name: 'OperationError', cause: err }); | 103 | | - }); | | 106 | + } | 104 | 107 |
| 105 | 108 | let publicUsages; | 106 | 109 | let privateUsages; | @@ -119,14 +122,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) { | 119 | 122 |
| 120 | 123 | const publicKey = | 121 | 124 | new InternalCryptoKey( | 122 | | - keypair.publicKey, | | 125 | + keyPair.publicKey, | 123 | 126 | keyAlgorithm, | 124 | 127 | publicUsages, | 125 | 128 | true); | 126 | 129 |
| 127 | 130 | const privateKey = | 128 | 131 | new InternalCryptoKey( | 129 | | - keypair.privateKey, | | 132 | + keyPair.privateKey, | 130 | 133 | keyAlgorithm, | 131 | 134 | privateUsages, | 132 | 135 | extractable); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/mac.js +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,11 +54,14 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) { | 54 | 54 | 'SyntaxError'); | 55 | 55 | } | 56 | 56 |
| 57 | | - const key = await generateKey('hmac', { length }).catch((err) => { | | 57 | + let key; | | 58 | + try { | | 59 | + key = await generateKey('hmac', { length }); | | 60 | + } catch (err) { | 58 | 61 | throw lazyDOMException( | 59 | 62 | 'The operation failed for an operation-specific reason', | 60 | 63 | { name: 'OperationError', cause: err }); | 61 | | - }); | | 64 | + } | 62 | 65 |
| 63 | 66 | return new InternalCryptoKey( | 64 | 67 | key, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/rsa.js +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -148,14 +148,17 @@ async function rsaKeyGenerate( | 148 | 148 | } | 149 | 149 | } | 150 | 150 |
| 151 | | - const keypair = await generateKeyPair('rsa', { | 152 | | - modulusLength, | 153 | | - publicExponent: publicExponentConverted, | 154 | | - }).catch((err) => { | | 151 | + let keyPair; | | 152 | + try { | | 153 | + keyPair = await generateKeyPair('rsa', { | | 154 | + modulusLength, | | 155 | + publicExponent: publicExponentConverted, | | 156 | + }); | | 157 | + } catch (err) { | 155 | 158 | throw lazyDOMException( | 156 | 159 | 'The operation failed for an operation-specific reason', | 157 | 160 | { name: 'OperationError', cause: err }); | 158 | | - }); | | 161 | + } | 159 | 162 |
| 160 | 163 | const keyAlgorithm = { | 161 | 164 | name, | @@ -181,14 +184,14 @@ async function rsaKeyGenerate( | 181 | 184 |
| 182 | 185 | const publicKey = | 183 | 186 | new InternalCryptoKey( | 184 | | - keypair.publicKey, | | 187 | + keyPair.publicKey, | 185 | 188 | keyAlgorithm, | 186 | 189 | publicUsages, | 187 | 190 | true); | 188 | 191 |
| 189 | 192 | const privateKey = | 190 | 193 | new InternalCryptoKey( | 191 | | - keypair.privateKey, | | 194 | + keyPair.privateKey, | 192 | 195 | keyAlgorithm, | 193 | 196 | privateUsages, | 194 | 197 | extractable); | |
|