grim/josetool

whitespace
draft
2017-02-07, Gary Kramlich
291d68fdd3a3
whitespace
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
)
var (
ecdsaCmd = app.Command("ecdsa", "generate an ecdsa key")
ecdsaAlgorithm = ecdsaCmd.Flag("algorithm", "the algorithm to use").Short('a').Default("ES256").Enum("ES256", "ES384", "ES512")
ecdsaCurve = ecdsaCmd.Arg("curve", "the curve to use").Default("P-384").Enum("P-256", "P-384", "P-521")
ecdsaKid = ecdsaCmd.Flag("key-id", "the key id to use").Short('i').String()
ecdsaUse = ecdsaCmd.Flag("use", "how this key will be used").Short('u').Default("sig").Enum("sig", "enc")
ecdsaFilename = ecdsaCmd.Flag("filename", "the base filename to output the key to").Short('f').Default("-").String()
)
func genECDSA() error {
curves := map[string]elliptic.Curve{
"P-256": elliptic.P256(),
"P-384": elliptic.P384(),
"P-521": elliptic.P521(),
}
cryptoCurve := curves[*ecdsaCurve]
priv, err := ecdsa.GenerateKey(cryptoCurve, rand.Reader)
if err != nil {
return err
}
return output(
priv,
priv.Public(),
*ecdsaFilename,
*ecdsaKid,
*ecdsaAlgorithm,
*ecdsaUse,
)
}