diff options
author | Jakob Borg <jakob@nym.se> | 2016-05-05 19:05:45 +0000 |
---|---|---|
committer | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2016-05-05 19:05:45 +0000 |
commit | 2ebc6996a24aa995e3633eacc03099a627516311 (patch) | |
tree | dcb90952a93e9d42a511e3c4c32c52503338468b | |
parent | 2e840134d2297bfa21900e5bd0b8288715221b46 (diff) |
cmd/stsigtool: Sign stdin when not given a file to sign, or when given "-"
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3041
-rw-r--r-- | cmd/stsigtool/main.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cmd/stsigtool/main.go b/cmd/stsigtool/main.go index e0688d4dbd..10969a98cb 100644 --- a/cmd/stsigtool/main.go +++ b/cmd/stsigtool/main.go @@ -8,6 +8,7 @@ package main import ( "flag" + "io" "io/ioutil" "log" "os" @@ -31,7 +32,7 @@ Where command is one of: gen - generate a new key pair - sign <privkeyfile> <datafile> + sign <privkeyfile> [datafile] - sign a file verify <signaturefile> <datafile> @@ -72,13 +73,19 @@ func sign(keyname, dataname string) { log.Fatal(err) } - fd, err := os.Open(dataname) - if err != nil { - log.Fatal(err) + var input io.Reader + if dataname == "-" || dataname == "" { + 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 { log.Fatal(err) } |