package main import ( "flag" "dim13.org/signify/ask" "dim13.org/signify/file" "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 := file.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 := file.EncodeFile(*secFile, file.ModeSec, secKey, *comment+" secret key", nil); err != nil { return err } if err := file.EncodeFile(*pubFile, file.ModePub, pubKey, *comment+" public key", nil); err != nil { return err } return nil }