GeezerVison is showing github.com — lib: prefer primordials in SubtleCrypto · nodejs/node@92ef2ad
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/cfrg.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | SafeSet, | | 5 | + StringPrototypeToLowerCase, | 5 | 6 | } = primordials; | 6 | 7 |
| 7 | 8 | const { Buffer } = require('buffer'); | @@ -332,7 +333,7 @@ function cfrgImportKey( | 332 | 333 | return undefined; | 333 | 334 | } | 334 | 335 |
| 335 | | - if (keyObject.asymmetricKeyType !== name.toLowerCase()) { | | 336 | + if (keyObject.asymmetricKeyType !== StringPrototypeToLowerCase(name)) { | 336 | 337 | throw lazyDOMException('Invalid key type', 'DataError'); | 337 | 338 | } | 338 | 339 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/ml_dsa.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | SafeSet, | | 5 | + StringPrototypeToLowerCase, | 5 | 6 | TypedArrayPrototypeGetBuffer, | 6 | 7 | TypedArrayPrototypeSet, | 7 | 8 | Uint8Array, | @@ -276,7 +277,7 @@ function mlDsaImportKey( | 276 | 277 | return undefined; | 277 | 278 | } | 278 | 279 |
| 279 | | - if (keyObject.asymmetricKeyType !== name.toLowerCase()) { | | 280 | + if (keyObject.asymmetricKeyType !== StringPrototypeToLowerCase(name)) { | 280 | 281 | throw lazyDOMException('Invalid key type', 'DataError'); | 281 | 282 | } | 282 | 283 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/ml_kem.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const { | 4 | 4 | PromiseWithResolvers, | 5 | 5 | SafeSet, | | 6 | + StringPrototypeToLowerCase, | 6 | 7 | TypedArrayPrototypeGetBuffer, | 7 | 8 | TypedArrayPrototypeSet, | 8 | 9 | Uint8Array, | @@ -209,7 +210,7 @@ function mlKemImportKey( | 209 | 210 | return undefined; | 210 | 211 | } | 211 | 212 |
| 212 | | - if (keyObject.asymmetricKeyType !== name.toLowerCase()) { | | 213 | + if (keyObject.asymmetricKeyType !== StringPrototypeToLowerCase(name)) { | 213 | 214 | throw lazyDOMException('Invalid key type', 'DataError'); | 214 | 215 | } | 215 | 216 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js +10-10Lines changed: 10 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ const { | 15 | 15 | ObjectEntries, | 16 | 16 | ObjectKeys, | 17 | 17 | ObjectPrototypeHasOwnProperty, | 18 | | - Promise, | | 18 | + PromiseWithResolvers, | 19 | 19 | StringPrototypeToUpperCase, | 20 | 20 | Symbol, | 21 | 21 | TypedArrayPrototypeGetBuffer, | @@ -656,15 +656,15 @@ function onDone(resolve, reject, err, result) { | 656 | 656 | } | 657 | 657 |
| 658 | 658 | function jobPromise(getJob) { | 659 | | - return new Promise((resolve, reject) => { | 660 | | - try { | 661 | | - const job = getJob(); | 662 | | - job.ondone = FunctionPrototypeBind(onDone, job, resolve, reject); | 663 | | - job.run(); | 664 | | - } catch (err) { | 665 | | - onDone(resolve, reject, err); | 666 | | - } | 667 | | - }); | | 659 | + const { promise, resolve, reject } = PromiseWithResolvers(); | | 660 | + try { | | 661 | + const job = getJob(); | | 662 | + job.ondone = FunctionPrototypeBind(onDone, job, resolve, reject); | | 663 | + job.run(); | | 664 | + } catch (err) { | | 665 | + onDone(resolve, reject, err); | | 666 | + } | | 667 | + return promise; | 668 | 668 | } | 669 | 669 |
| 670 | 670 | // In WebCrypto, the publicExponent option in RSA is represented as a | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/webidl.js +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -195,12 +195,14 @@ converters.object = (V, opts) => { | 195 | 195 |
| 196 | 196 | const isNonSharedArrayBuffer = isArrayBuffer; | 197 | 197 |
| | 198 | +/** | | 199 | + * @param {string | object} V - The hash algorithm identifier (string or object). | | 200 | + * @param {string} label - The dictionary name for the error message. | | 201 | + */ | 198 | 202 | function ensureSHA(V, label) { | 199 | | - if ( | 200 | | - typeof V === 'string' ? | 201 | | - !StringPrototypeStartsWith(StringPrototypeToLowerCase(V), 'sha') : | 202 | | - V.name?.toLowerCase?.().startsWith('sha') === false | 203 | | - ) | | 203 | + const name = typeof V === 'string' ? V : V.name; | | 204 | + if (typeof name !== 'string' || | | 205 | + !StringPrototypeStartsWith(StringPrototypeToLowerCase(name), 'sha')) | 204 | 206 | throw lazyDOMException( | 205 | 207 | `Only SHA hashes are supported in ${label}`, 'NotSupportedError'); | 206 | 208 | } | |
|