diff --git a/src/lib/decrypt_transform.ts b/src/lib/decrypt_transform.ts index 525c67c..5cd2ad3 100644 --- a/src/lib/decrypt_transform.ts +++ b/src/lib/decrypt_transform.ts @@ -24,8 +24,8 @@ export class DecryptTransform extends Transform { override _transform(chunk: any, _encoding: BufferEncoding, callback: TransformCallback) { let data = chunk as Buffer - if (this.inputEncoding && this.inputEncoding !== 'binary') { - data = Buffer.from(data.toString().trim(), this.inputEncoding) + if (this.inputEncoding) { + data = Buffer.from(data.toString(), this.inputEncoding) } if (!this.decipher) { // Unpackage the combined iv + encrypted message. diff --git a/test/ssh_agent_cli.spec.ts b/test/ssh_agent_cli.spec.ts index f6cf369..3aa053b 100644 --- a/test/ssh_agent_cli.spec.ts +++ b/test/ssh_agent_cli.spec.ts @@ -4,8 +4,9 @@ import { execSync } from 'child_process' describe('ssh-crypt cli tests', () => { it('should show help', () => { - const output = execSync(`npm exec -- tsx src/cli.ts -h`, { + const output = execSync('npm exec -- tsx src/cli.ts -h', { encoding: 'utf8', + stdio: 'pipe', }) const text = 'Usage: ssh-crypt [options] \n' + @@ -30,9 +31,11 @@ describe('ssh-crypt cli tests', () => { }) it('should encrypt', () => { const output = execSync( - `echo 'Lorem ipsum dolor' | npm exec -- tsx src/cli.ts -k key_ed25519 -s not_a_secret --encryptEncoding hex encrypt`, + 'npm exec -- tsx src/cli.ts -k key_ed25519 -s not_a_secret --encryptEncoding hex encrypt', { encoding: 'ascii', + input: 'Lorem ipsum dolor', + stdio: 'pipe', }, ) chai.assert.strictEqual(output.length, 96) @@ -41,9 +44,11 @@ describe('ssh-crypt cli tests', () => { const data = 'ecfd6bb57f4891ba7226886e90d2eb848022a495b15ffd91ffe760bca5605f9062c305ee14226d9daf7faa58460c8f50' const output = execSync( - `echo '${data}' | npm exec -- tsx src/cli.ts -k key_rsa -s not_a_secret --decryptEncoding hex decrypt`, + 'npm exec -- tsx src/cli.ts -k key_rsa -s not_a_secret --decryptEncoding hex decrypt', { encoding: 'utf8', + input: data, + stdio: 'pipe', }, ) chai.assert.strictEqual(output, 'Lorem ipsum dolor') @@ -53,9 +58,10 @@ describe('ssh-crypt cli tests', () => { 'ecfd6bb57f4891ba7226886e90d2eb848022a495b15ffd91ffe760bca5605f9062c305ee14226d9daf7faa58460c8f50' chai .expect(() => - execSync( - `echo '${data}' | npm exec -- tsx src/cli.ts -k key_rsa -s wrong_secret --decryptEncoding hex decrypt`, - ), + execSync('npm exec -- tsx src/cli.ts -k key_rsa -s wrong_secret --decryptEncoding hex decrypt', { + input: data, + stdio: 'pipe', + }), ) .to.throw(/bad secret or key, can't decrypt/iu) })