| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ad5dcc5 commit 7611fc1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -215,7 +215,7 @@ Buffer<void> DataPointer::release() { | |||
| 215 | 215 | DataPointer DataPointer::resize(size_t len) { | |
| 216 | 216 | size_t actual_len = std::min(len_, len); | |
| 217 | 217 | auto buf = release(); | |
| 218 | - if (actual_len == len_) return DataPointer(buf); | ||
| 218 | + if (actual_len == len_) return DataPointer(buf.data, actual_len); | ||
| 219 | 219 | buf.data = OPENSSL_realloc(buf.data, actual_len); | |
| 220 | 220 | buf.len = actual_len; | |
| 221 | 221 | return DataPointer(buf); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,56 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + if (!common.hasCrypto) | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + | ||
| 7 | + const fixtures = require('../common/fixtures'); | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + const crypto = require('crypto'); | ||
| 10 | + | ||
| 11 | + const { subtle } = globalThis.crypto; | ||
| 12 | + | ||
| 13 | + // Regression test for https://github.com/nodejs/node/issues/57553. | ||
| 14 | + { | ||
| 15 | + const privateKey = crypto.createPrivateKey(fixtures.readKey('rsa_private.pem', 'ascii')); | ||
| 16 | + const publicKey = crypto.createPublicKey(fixtures.readKey('rsa_public.pem', 'ascii')); | ||
| 17 | + | ||
| 18 | + const data = Buffer.alloc(0); | ||
| 19 | + { | ||
| 20 | + | ||
| 21 | + const ciphertext = crypto.publicEncrypt({ | ||
| 22 | + padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, | ||
| 23 | + key: publicKey, | ||
| 24 | + }, data); | ||
| 25 | + | ||
| 26 | + const plaintext = crypto.privateDecrypt({ | ||
| 27 | + padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, | ||
| 28 | + key: privateKey | ||
| 29 | + }, ciphertext); | ||
| 30 | + | ||
| 31 | + assert.deepStrictEqual(plaintext, data); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + { | ||
| 35 | + const ciphertext = crypto.publicEncrypt(publicKey, data); | ||
| 36 | + const plaintext = crypto.privateDecrypt(privateKey, ciphertext); | ||
| 37 | + | ||
| 38 | + assert.deepStrictEqual(plaintext, data); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + { | ||
| 42 | + (async () => { | ||
| 43 | + const pkcs8 = privateKey.export({ format: 'der', type: 'pkcs8' }); | ||
| 44 | + const spki = publicKey.export({ format: 'der', type: 'spki' }); | ||
| 45 | + | ||
| 46 | + const kp = { | ||
| 47 | + privateKey: await subtle.importKey('pkcs8', pkcs8, { name: 'RSA-OAEP', hash: 'SHA-1' }, false, ['decrypt']), | ||
| 48 | + publicKey: await subtle.importKey('spki', spki, { name: 'RSA-OAEP', hash: 'SHA-1' }, false, ['encrypt']), | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + const ciphertext = await subtle.encrypt('RSA-OAEP', kp.publicKey, data); | ||
| 52 | + const plaintext = await subtle.decrypt('RSA-OAEP', kp.privateKey, ciphertext); | ||
| 53 | + assert.deepStrictEqual(plaintext, data.buffer); | ||
| 54 | + })().then(common.mustCall()); | ||
| 55 | + } | ||
| 56 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments