Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/lib/decrypt_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions test/ssh_agent_cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] <command>\n' +
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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)
})
Expand Down