| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2a6e605 commit ad98b46
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6132,7 +6132,7 @@ changes: | |||
| 6132 | 6132 | <!--lint disable maximum-line-length remark-lint--> | |
| 6133 | 6133 | ||
| 6134 | 6134 | * `algorithm` {string | null | undefined} | |
| 6135 | - * `data` {ArrayBuffer|Buffer|TypedArray|DataView} | ||
| 6135 | + * `data` {ArrayBuffer|Buffer|SharedArrayBuffer|TypedArray|DataView|string} | ||
| 6136 | 6136 | * `key` {Object|string|ArrayBuffer|Buffer|TypedArray|DataView|KeyObject|CryptoKey} | |
| 6137 | 6137 | * `callback` {Function} | |
| 6138 | 6138 | * `err` {Error} | |
@@ -6264,9 +6264,9 @@ changes: | |||
| 6264 | 6264 | <!--lint disable maximum-line-length remark-lint--> | |
| 6265 | 6265 | ||
| 6266 | 6266 | * `algorithm` {string|null|undefined} | |
| 6267 | - * `data` {ArrayBuffer| Buffer|TypedArray|DataView} | ||
| 6267 | + * `data` {ArrayBuffer|Buffer|SharedArrayBuffer|TypedArray|DataView|string} | ||
| 6268 | 6268 | * `key` {Object|string|ArrayBuffer|Buffer|TypedArray|DataView|KeyObject|CryptoKey} | |
| 6269 | - * `signature` {ArrayBuffer|Buffer|TypedArray|DataView} | ||
| 6269 | + * `signature` {ArrayBuffer|Buffer|SharedArrayBuffer|TypedArray|DataView} | ||
| 6270 | 6270 | * `callback` {Function} | |
| 6271 | 6271 | * `err` {Error} | |
| 6272 | 6272 | * `result` {boolean} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -265,14 +265,6 @@ function verifyOneShot(algorithm, data, key, signature, callback) { | |||
| 265 | 265 | ||
| 266 | 266 | data = getArrayBufferOrView(data, 'data'); | |
| 267 | 267 | ||
| 268 | - if (!isArrayBufferView(data)) { | ||
| 269 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 270 | - 'data', | ||
| 271 | - ['Buffer', 'TypedArray', 'DataView'], | ||
| 272 | - data, | ||
| 273 | - ); | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | 268 | // Options specific to RSA | |
| 277 | 269 | const rsaPadding = getPadding(key); | |
| 278 | 270 | const pssSaltLength = getSaltLength(key); | |
@@ -283,13 +275,7 @@ function verifyOneShot(algorithm, data, key, signature, callback) { | |||
| 283 | 275 | // Options specific to Ed448 and ML-DSA | |
| 284 | 276 | const context = getContext(key); | |
| 285 | 277 | ||
| 286 | - if (!isArrayBufferView(signature)) { | ||
| 287 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 288 | - 'signature', | ||
| 289 | - ['Buffer', 'TypedArray', 'DataView'], | ||
| 290 | - signature, | ||
| 291 | - ); | ||
| 292 | - } | ||
| 278 | + signature = getArrayBufferOrView(signature, 'signature'); | ||
| 293 | 279 | ||
| 294 | 280 | const { | |
| 295 | 281 | data: keyData, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -619,8 +619,8 @@ if (hasOpenSSL(3, 2)) { | |||
| 619 | 619 | assert.throws(() => crypto.sign(null, data, input), errObj); | |
| 620 | 620 | assert.throws(() => crypto.verify(null, data, input, sig), errObj); | |
| 621 | 621 | ||
| 622 | - errObj.message = 'The "signature" argument must be an instance of ' + | ||
| 623 | - 'Buffer, TypedArray, or DataView.' + | ||
| 622 | + errObj.message = 'The "signature" argument must be of type string or an instance of ' + | ||
| 623 | + 'ArrayBuffer, Buffer, TypedArray, or DataView.' + | ||
| 624 | 624 | common.invalidArgTypeHelper(input); | |
| 625 | 625 | assert.throws(() => crypto.verify(null, data, 'test', input), errObj); | |
| 626 | 626 | }); | |
@@ -1019,3 +1019,39 @@ if (!process.features.openssl_is_boringssl) { | |||
| 1019 | 1019 | message: /key\.format/, | |
| 1020 | 1020 | }); | |
| 1021 | 1021 | } | |
| 1022 | + | ||
| 1023 | + // crypto.verify accepts ArrayBuffer and SharedArrayBuffer for data and signature | ||
| 1024 | + { | ||
| 1025 | + const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048 }); | ||
| 1026 | + const dataBuffer = Buffer.from('Hello world'); | ||
| 1027 | + | ||
| 1028 | + // Data as ArrayBuffer | ||
| 1029 | + { | ||
| 1030 | + const ab = dataBuffer.buffer.slice(dataBuffer.byteOffset, dataBuffer.byteOffset + dataBuffer.byteLength); | ||
| 1031 | + const sig = crypto.sign('SHA256', dataBuffer, privateKey); | ||
| 1032 | + assert.strictEqual(crypto.verify('SHA256', ab, publicKey, sig), true); | ||
| 1033 | + } | ||
| 1034 | + | ||
| 1035 | + // Data as SharedArrayBuffer | ||
| 1036 | + { | ||
| 1037 | + const sab = new SharedArrayBuffer(dataBuffer.length); | ||
| 1038 | + new Uint8Array(sab).set(dataBuffer); | ||
| 1039 | + const sig = crypto.sign('SHA256', dataBuffer, privateKey); | ||
| 1040 | + assert.strictEqual(crypto.verify('SHA256', sab, publicKey, sig), true); | ||
| 1041 | + } | ||
| 1042 | + | ||
| 1043 | + // Signature as ArrayBuffer | ||
| 1044 | + { | ||
| 1045 | + const sig = crypto.sign('SHA256', dataBuffer, privateKey); | ||
| 1046 | + const sigAB = sig.buffer.slice(sig.byteOffset, sig.byteOffset + sig.byteLength); | ||
| 1047 | + assert.strictEqual(crypto.verify('SHA256', dataBuffer, publicKey, sigAB), true); | ||
| 1048 | + } | ||
| 1049 | + | ||
| 1050 | + // Signature as SharedArrayBuffer | ||
| 1051 | + { | ||
| 1052 | + const sig = crypto.sign('SHA256', dataBuffer, privateKey); | ||
| 1053 | + const sigSAB = new SharedArrayBuffer(sig.length); | ||
| 1054 | + new Uint8Array(sigSAB).set(sig); | ||
| 1055 | + assert.strictEqual(crypto.verify('SHA256', dataBuffer, publicKey, sigSAB), true); | ||
| 1056 | + } | ||
| 1057 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments