0
0
Fork 0

add public key support

This adds all options to create and store a public key.
This commit is contained in:
Gibheer 2015-02-17 21:44:10 +01:00
parent b022e8ab4c
commit 470d21409b
3 changed files with 14 additions and 8 deletions

View File

@ -51,7 +51,7 @@ type (
// a container for the refined flags
flagSet struct {
PrivateKey pkilib.PrivateKey
PrivateKey pki.PrivateKey
Output io.WriteCloser
// private key specific stuff

14
main.go
View File

@ -50,10 +50,10 @@ func create_private_key() {
err := fs.Parse(program_args())
if err != nil { crash_with_help(1, fmt.Sprintf("%s", err)) }
var pk pkilib.Pemmer
var pk pki.Pemmer
switch fs.Flags.PrivateKeyGenerationFlags.Type {
case "ecdsa": pk, err = pkilib.NewPrivateKeyEcdsa(fs.Flags.PrivateKeyGenerationFlags.Curve)
case "rsa": pk, err = pkilib.NewPrivateKeyRsa(fs.Flags.PrivateKeyGenerationFlags.Size)
case "ecdsa": pk, err = pki.NewPrivateKeyEcdsa(fs.Flags.PrivateKeyGenerationFlags.Curve)
case "rsa": pk, err = pki.NewPrivateKeyRsa(fs.Flags.PrivateKeyGenerationFlags.Size)
}
if err != nil { crash_with_help(2, fmt.Sprintf("%s", err)) }
marsh_pem, err := pk.MarshalPem()
@ -66,10 +66,16 @@ func create_private_key() {
func create_public_key() {
fs := NewFlags("create-public")
fs.AddPrivateKey()
fs.AddOutput()
err := fs.Parse(program_args())
if err != nil { crash_with_help(1, fmt.Sprintf("%s", err)) }
fmt.Println(fs.Flags.PrivateKey.Public())
var pub_key pki.Pemmer
pub_key = fs.Flags.PrivateKey.Public()
marsh_pem, err := pub_key.MarshalPem()
if err != nil { crash_with_help(2, fmt.Sprintf("%s", err)) }
_, err = marsh_pem.WriteTo(fs.Flags.Output)
if err != nil { crash_with_help(2, fmt.Sprintf("%s", err)) }
}
// print the module help

View File

@ -16,16 +16,16 @@ var (
// Read the private key from the path and try to figure out which type of key it
// might be.
func ReadPrivateKeyFile(path string) (pkilib.PrivateKey, error) {
func ReadPrivateKeyFile(path string) (pki.PrivateKey, error) {
raw_pk, err := readSectionFromFile(path, TypeLabelECDSA)
if err == nil {
pk, err := pkilib.LoadPrivateKeyEcdsa(raw_pk)
pk, err := pki.LoadPrivateKeyEcdsa(raw_pk)
if err != nil { return nil, err }
return pk, nil
}
raw_pk, err = readSectionFromFile(path, TypeLabelRSA)
if err == nil {
pk, err := pkilib.LoadPrivateKeyRsa(raw_pk)
pk, err := pki.LoadPrivateKeyRsa(raw_pk)
if err != nil { return nil, err }
return pk, nil
}