22
33import { Argument , Option , program } from '@commander-js/extra-typings'
44import { createReadStream , createWriteStream } from 'node:fs'
5+ import { pipeline } from 'node:stream/promises'
56import { SSHAgentClient } from './lib/ssh_agent_client.js'
67
78program
@@ -23,13 +24,18 @@ program
2324 }
2425 const readable = options . input ? createReadStream ( options . input ) : process . stdin
2526 const writable = options . output ? createWriteStream ( options . output ) : process . stdout
26- const transform =
27+ const getTransform =
2728 action === 'decrypt'
28- ? await agent . getDecryptTransform ( key , options . seed , options . decryptEncoding )
29- : await agent . getEncryptTransform ( key , options . seed , options . encryptEncoding )
30- readable . pipe ( transform ) . pipe ( writable )
29+ ? agent . getDecryptTransform ( key , options . seed , options . decryptEncoding )
30+ : agent . getEncryptTransform ( key , options . seed , options . encryptEncoding )
31+ await getTransform . then ( transform => pipeline ( readable , transform , writable ) )
3132 } catch ( err ) {
32- program . error ( `Error: ${ ( err as Error ) . message } ` )
33+ const error = err as Error
34+ if ( 'code' in error && error . code === 'ERR_OSSL_BAD_DECRYPT' ) {
35+ program . error ( "Bad secret or key, can't decrypt" )
36+ } else {
37+ program . error ( `Error: ${ error . message } ` )
38+ }
3339 }
3440 } )
3541
0 commit comments