package main import ( "flag" "dim13.org/signify/ask" "dim13.org/signify/b64file" "dim13.org/signify/key" ) // Usage: signify -G [-n] [-c comment] -p pubkey -s seckey func generate(args []string) error { opts := flag.NewFlagSet("generate", flag.ExitOnError) var ( nopass = opts.Bool("n", false, "No key passphrase") comment = opts.String("c", "signify", "Comment") pubFile = opts.String("p", "", "Public key file (required)") secFile = opts.String("s", "", "Secret key file (required)") ) opts.Parse(args) if *pubFile == "" || *secFile == "" { opts.Usage() return nil } if err := ValidateNames(*pubFile, *secFile); err != nil { return err } var der key.Deriver if !*nopass { der = ask.Confirmed{} } pubKey, secKey, err := key.Generate(der) if err != nil { return err } if err := encodeSec(*secFile, *comment+" secret key", secKey); err != nil { return err } if err := encodePub(*pubFile, *comment+" public key", pubKey); err != nil { return err } return nil } func encodeSec(fname, comment string, sig *key.Sec) error { fd, err := Create(fname, ModeSec) if err != nil { return err } defer fd.Close() return b64file.Encode(fd, sig, comment+" secret key", nil) } func encodePub(fname, comment string, pub *key.Pub) error { fd, err := Create(fname, ModePub) if err != nil { return err } defer fd.Close() return b64file.Encode(fd, pub, comment+" public key", nil) }