summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Borg <jakob@nym.se>2016-05-05 19:05:45 +0000
committerAudrius Butkevicius <audrius.butkevicius@gmail.com>2016-05-05 19:05:45 +0000
commit2ebc6996a24aa995e3633eacc03099a627516311 (patch)
treedcb90952a93e9d42a511e3c4c32c52503338468b
parent2e840134d2297bfa21900e5bd0b8288715221b46 (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.go19
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)
}