mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
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:
parent
2e840134d2
commit
2ebc6996a2
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user