added show command and command handling
This commit is contained in:
parent
b9cb91c4e1
commit
43f8927a1c
@ -608,14 +608,24 @@ func Sign(input *Input, url string, pk ed25519.PrivateKey) ([]SignOperation, err
|
||||
}
|
||||
|
||||
var (
|
||||
injson = flag.String("input", "-", "input json for signing")
|
||||
keyfile = flag.String("key", "auditor.key", "filename of EC25519 private key")
|
||||
url = flag.String("url", "https://auditor.codeblau.de/", "auditor url")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n %s [Options] (show|sign)\nOptions:\n", os.Args[0], os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
if len(flag.Args()) == 0 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(*keyfile) == 0 {
|
||||
log.Println("keyfile needed")
|
||||
return
|
||||
@ -626,10 +636,29 @@ func main() {
|
||||
log.Printf("couldn't read keyfile: %v\n", e)
|
||||
return
|
||||
}
|
||||
|
||||
pk := ed25519.NewKeyFromSeed(k)
|
||||
pub := (pk.Public()).(ed25519.PublicKey)
|
||||
pe, _ := crockfordEncode(pub)
|
||||
|
||||
switch flag.Arg(0) {
|
||||
case "show":
|
||||
fmt.Printf("public key: %s\n", string(pe))
|
||||
case "sign":
|
||||
var dec *json.Decoder
|
||||
|
||||
input := new(Input)
|
||||
dec := json.NewDecoder(os.Stdin)
|
||||
if *injson == "-" {
|
||||
dec = json.NewDecoder(os.Stdin)
|
||||
} else {
|
||||
f, e := os.Open(*injson)
|
||||
if e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
dec = json.NewDecoder(f)
|
||||
}
|
||||
e = dec.Decode(input)
|
||||
if e != nil {
|
||||
log.Fatal(e)
|
||||
@ -646,5 +675,9 @@ func main() {
|
||||
if e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
default:
|
||||
flag.Usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user