Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test to eliminate duplicate statements #28342

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions test/parallel/test-crypto-rsa-dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const decryptError = {
{
const input = 'I AM THE WALRUS';
const bufferToEncrypt = Buffer.from(input);
const bufferPassword = Buffer.from('password');

let encryptedBuffer = crypto.publicEncrypt(rsaPubPem, bufferToEncrypt);

Expand Down Expand Up @@ -66,33 +67,33 @@ const decryptError = {

encryptedBuffer = crypto.privateEncrypt({
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, bufferToEncrypt);

decryptedBufferWithPassword = crypto.publicDecrypt({
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), input);

// Now with explicit RSA_PKCS1_PADDING.
encryptedBuffer = crypto.privateEncrypt({
padding: crypto.constants.RSA_PKCS1_PADDING,
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, bufferToEncrypt);

decryptedBufferWithPassword = crypto.publicDecrypt({
padding: crypto.constants.RSA_PKCS1_PADDING,
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), input);

// Omitting padding should be okay because RSA_PKCS1_PADDING is the default.
decryptedBufferWithPassword = crypto.publicDecrypt({
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), input);

Expand All @@ -101,13 +102,13 @@ const decryptError = {
encryptedBuffer = crypto.privateEncrypt({
padding: crypto.constants.RSA_NO_PADDING,
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, Buffer.from(plaintext));

decryptedBufferWithPassword = crypto.publicDecrypt({
padding: crypto.constants.RSA_NO_PADDING,
key: rsaKeyPemEncrypted,
passphrase: Buffer.from('password')
passphrase: bufferPassword
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), plaintext);

Expand Down