Teach dec to run in test-only mode

This commit is contained in:
Sudhi Herle 2019-11-08 10:49:13 -08:00
parent a9c17988c4
commit 0abbfd37ec
2 changed files with 23 additions and 4 deletions

View file

@ -186,6 +186,18 @@ func encrypt(args []string) {
} }
} }
type nullWriter struct{}
func (w *nullWriter) Write(p []byte) (int, error) {
return len(p), nil
}
func (w *nullWriter) Close() error {
return nil
}
var _ io.WriteCloser = &nullWriter{}
// sigtool decrypt a.key [file] [-o output] // sigtool decrypt a.key [file] [-o output]
func decrypt(args []string) { func decrypt(args []string) {
fs := flag.NewFlagSet("decrypt", flag.ExitOnError) fs := flag.NewFlagSet("decrypt", flag.ExitOnError)
@ -196,12 +208,13 @@ func decrypt(args []string) {
var envpw string var envpw string
var outfile string var outfile string
var pubkey string var pubkey string
var nopw bool var nopw, test bool
fs.StringVarP(&outfile, "outfile", "o", "", "Write the output to file `F`") fs.StringVarP(&outfile, "outfile", "o", "", "Write the output to file `F`")
fs.BoolVarP(&nopw, "no-password", "", false, "Don't ask for passphrase to decrypt the private key") fs.BoolVarP(&nopw, "no-password", "", false, "Don't ask for passphrase to decrypt the private key")
fs.StringVarP(&envpw, "env-password", "", "", "Use passphrase from environment variable `E`") fs.StringVarP(&envpw, "env-password", "", "", "Use passphrase from environment variable `E`")
fs.StringVarP(&pubkey, "verify-sender", "v", "", "Verify that the sender matches public key in `F`") fs.StringVarP(&pubkey, "verify-sender", "v", "", "Verify that the sender matches public key in `F`")
fs.BoolVarP(&test, "test", "t", false, "Test the encrypted file against the given key without writing to output")
err := fs.Parse(args) err := fs.Parse(args)
if err != nil { if err != nil {
@ -258,7 +271,9 @@ func decrypt(args []string) {
} }
} }
if len(outfile) > 0 && outfile != "-" { if test {
outfd = &nullWriter{}
} else if len(outfile) > 0 && outfile != "-" {
if inf != nil { if inf != nil {
ost, err := os.Stat(outfile) ost, err := os.Stat(outfile)
if err != nil { if err != nil {
@ -293,6 +308,10 @@ func decrypt(args []string) {
if err != nil { if err != nil {
die("%s", err) die("%s", err)
} }
if test {
warn("Enc file OK")
}
} }
func encryptUsage(fs *flag.FlagSet) { func encryptUsage(fs *flag.FlagSet) {

View file

@ -1 +1 @@
0.5.0 0.5.1