test: eliminate duplicate statements
PR-URL: https://github.com/nodejs/node/pull/28342 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
23416936bc
commit
a10962187f
@ -38,6 +38,7 @@ const decryptError = {
|
|||||||
{
|
{
|
||||||
const input = 'I AM THE WALRUS';
|
const input = 'I AM THE WALRUS';
|
||||||
const bufferToEncrypt = Buffer.from(input);
|
const bufferToEncrypt = Buffer.from(input);
|
||||||
|
const bufferPassword = Buffer.from('password');
|
||||||
|
|
||||||
let encryptedBuffer = crypto.publicEncrypt(rsaPubPem, bufferToEncrypt);
|
let encryptedBuffer = crypto.publicEncrypt(rsaPubPem, bufferToEncrypt);
|
||||||
|
|
||||||
@ -66,12 +67,12 @@ const decryptError = {
|
|||||||
|
|
||||||
encryptedBuffer = crypto.privateEncrypt({
|
encryptedBuffer = crypto.privateEncrypt({
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, bufferToEncrypt);
|
}, bufferToEncrypt);
|
||||||
|
|
||||||
decryptedBufferWithPassword = crypto.publicDecrypt({
|
decryptedBufferWithPassword = crypto.publicDecrypt({
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, encryptedBuffer);
|
}, encryptedBuffer);
|
||||||
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
||||||
|
|
||||||
@ -79,20 +80,20 @@ const decryptError = {
|
|||||||
encryptedBuffer = crypto.privateEncrypt({
|
encryptedBuffer = crypto.privateEncrypt({
|
||||||
padding: crypto.constants.RSA_PKCS1_PADDING,
|
padding: crypto.constants.RSA_PKCS1_PADDING,
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, bufferToEncrypt);
|
}, bufferToEncrypt);
|
||||||
|
|
||||||
decryptedBufferWithPassword = crypto.publicDecrypt({
|
decryptedBufferWithPassword = crypto.publicDecrypt({
|
||||||
padding: crypto.constants.RSA_PKCS1_PADDING,
|
padding: crypto.constants.RSA_PKCS1_PADDING,
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, encryptedBuffer);
|
}, encryptedBuffer);
|
||||||
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
||||||
|
|
||||||
// Omitting padding should be okay because RSA_PKCS1_PADDING is the default.
|
// Omitting padding should be okay because RSA_PKCS1_PADDING is the default.
|
||||||
decryptedBufferWithPassword = crypto.publicDecrypt({
|
decryptedBufferWithPassword = crypto.publicDecrypt({
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, encryptedBuffer);
|
}, encryptedBuffer);
|
||||||
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
|
||||||
|
|
||||||
@ -101,13 +102,13 @@ const decryptError = {
|
|||||||
encryptedBuffer = crypto.privateEncrypt({
|
encryptedBuffer = crypto.privateEncrypt({
|
||||||
padding: crypto.constants.RSA_NO_PADDING,
|
padding: crypto.constants.RSA_NO_PADDING,
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, Buffer.from(plaintext));
|
}, Buffer.from(plaintext));
|
||||||
|
|
||||||
decryptedBufferWithPassword = crypto.publicDecrypt({
|
decryptedBufferWithPassword = crypto.publicDecrypt({
|
||||||
padding: crypto.constants.RSA_NO_PADDING,
|
padding: crypto.constants.RSA_NO_PADDING,
|
||||||
key: rsaKeyPemEncrypted,
|
key: rsaKeyPemEncrypted,
|
||||||
passphrase: Buffer.from('password')
|
passphrase: bufferPassword
|
||||||
}, encryptedBuffer);
|
}, encryptedBuffer);
|
||||||
assert.strictEqual(decryptedBufferWithPassword.toString(), plaintext);
|
assert.strictEqual(decryptedBufferWithPassword.toString(), plaintext);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user