cmd/stsigtool: Sign stdin when not given a file to sign, or when given "-"

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3041
This commit is contained in:
Jakob Borg 2016-05-05 19:05:45 +00:00 committed by Audrius Butkevicius
parent 2e840134d2
commit 2ebc6996a2

View File

@ -8,6 +8,7 @@ package main
import ( import (
"flag" "flag"
"io"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
@ -31,7 +32,7 @@ Where command is one of:
gen gen
- generate a new key pair - generate a new key pair
sign <privkeyfile> <datafile> sign <privkeyfile> [datafile]
- sign a file - sign a file
verify <signaturefile> <datafile> verify <signaturefile> <datafile>
@ -72,13 +73,19 @@ func sign(keyname, dataname string) {
log.Fatal(err) log.Fatal(err)
} }
fd, err := os.Open(dataname) var input io.Reader
if err != nil { if dataname == "-" || dataname == "" {
log.Fatal(err) input = os.Stdin
} else {
fd, err := os.Open(dataname)
if err != nil {
log.Fatal(err)
}
defer fd.Close()
input = fd
} }
defer fd.Close()
sig, err := signature.Sign(privkey, fd) sig, err := signature.Sign(privkey, input)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }