Skip to content

Commit 34731fd

Browse files
committed
remove useless trim
1 parent 0bd1917 commit 34731fd

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/lib/decrypt_transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class DecryptTransform extends Transform {
2424

2525
override _transform(chunk: any, _encoding: BufferEncoding, callback: TransformCallback) {
2626
let data = chunk as Buffer
27-
if (this.inputEncoding && this.inputEncoding !== 'binary') {
28-
data = Buffer.from(data.toString().trim(), this.inputEncoding)
27+
if (this.inputEncoding) {
28+
data = Buffer.from(data.toString(), this.inputEncoding)
2929
}
3030
if (!this.decipher) {
3131
// Unpackage the combined iv + encrypted message.

test/ssh_agent_cli.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { execSync } from 'child_process'
44

55
describe('ssh-crypt cli tests', () => {
66
it('should show help', () => {
7-
const output = execSync(`npm exec -- tsx src/cli.ts -h`, {
7+
const output = execSync('npm exec -- tsx src/cli.ts -h', {
88
encoding: 'utf8',
9+
stdio: 'pipe',
910
})
1011
const text =
1112
'Usage: ssh-crypt [options] <command>\n' +
@@ -30,9 +31,11 @@ describe('ssh-crypt cli tests', () => {
3031
})
3132
it('should encrypt', () => {
3233
const output = execSync(
33-
`echo 'Lorem ipsum dolor' | npm exec -- tsx src/cli.ts -k key_ed25519 -s not_a_secret --encryptEncoding hex encrypt`,
34+
'npm exec -- tsx src/cli.ts -k key_ed25519 -s not_a_secret --encryptEncoding hex encrypt',
3435
{
3536
encoding: 'ascii',
37+
input: 'Lorem ipsum dolor',
38+
stdio: 'pipe',
3639
},
3740
)
3841
chai.assert.strictEqual(output.length, 96)
@@ -41,9 +44,11 @@ describe('ssh-crypt cli tests', () => {
4144
const data =
4245
'ecfd6bb57f4891ba7226886e90d2eb848022a495b15ffd91ffe760bca5605f9062c305ee14226d9daf7faa58460c8f50'
4346
const output = execSync(
44-
`echo '${data}' | npm exec -- tsx src/cli.ts -k key_rsa -s not_a_secret --decryptEncoding hex decrypt`,
47+
'npm exec -- tsx src/cli.ts -k key_rsa -s not_a_secret --decryptEncoding hex decrypt',
4548
{
4649
encoding: 'utf8',
50+
input: data,
51+
stdio: 'pipe',
4752
},
4853
)
4954
chai.assert.strictEqual(output, 'Lorem ipsum dolor')
@@ -53,9 +58,10 @@ describe('ssh-crypt cli tests', () => {
5358
'ecfd6bb57f4891ba7226886e90d2eb848022a495b15ffd91ffe760bca5605f9062c305ee14226d9daf7faa58460c8f50'
5459
chai
5560
.expect(() =>
56-
execSync(
57-
`echo '${data}' | npm exec -- tsx src/cli.ts -k key_rsa -s wrong_secret --decryptEncoding hex decrypt`,
58-
),
61+
execSync('npm exec -- tsx src/cli.ts -k key_rsa -s wrong_secret --decryptEncoding hex decrypt', {
62+
input: data,
63+
stdio: 'pipe',
64+
}),
5965
)
6066
.to.throw(/bad secret or key, can't decrypt/iu)
6167
})

0 commit comments

Comments
 (0)