added show command and command handling

This commit is contained in:
Özgür Kesim 2021-11-21 11:39:15 +01:00
parent b9cb91c4e1
commit 43f8927a1c
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7

View File

@ -608,14 +608,24 @@ func Sign(input *Input, url string, pk ed25519.PrivateKey) ([]SignOperation, err
} }
var ( var (
injson = flag.String("input", "-", "input json for signing")
keyfile = flag.String("key", "auditor.key", "filename of EC25519 private key") keyfile = flag.String("key", "auditor.key", "filename of EC25519 private key")
url = flag.String("url", "https://auditor.codeblau.de/", "auditor url") url = flag.String("url", "https://auditor.codeblau.de/", "auditor url")
) )
func main() { 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() flag.Parse()
if len(flag.Args()) == 0 {
flag.Usage()
os.Exit(1)
}
if len(*keyfile) == 0 { if len(*keyfile) == 0 {
log.Println("keyfile needed") log.Println("keyfile needed")
return return
@ -626,10 +636,29 @@ func main() {
log.Printf("couldn't read keyfile: %v\n", e) log.Printf("couldn't read keyfile: %v\n", e)
return return
} }
pk := ed25519.NewKeyFromSeed(k) 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) 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) e = dec.Decode(input)
if e != nil { if e != nil {
log.Fatal(e) log.Fatal(e)
@ -646,5 +675,9 @@ func main() {
if e != nil { if e != nil {
log.Fatal(e) log.Fatal(e)
} }
default:
flag.Usage()
os.Exit(2)
}
} }