From 470d21409b5f26d49fefd34d75b82197045d4811 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 17 Feb 2015 21:44:10 +0100 Subject: add public key support This adds all options to create and store a public key. --- main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 56128ff..524f498 100644 --- a/main.go +++ b/main.go @@ -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 -- cgit v1.2.3-70-g09d2