diff options
author | Gibheer <gibheer@gmail.com> | 2015-02-15 01:34:25 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2015-02-15 01:34:25 +0100 |
commit | 16eb14db9f9b228ef88bcf1beb09cf823256dac1 (patch) | |
tree | 414ed9ba9f3e5679a7b0ae7b120e752d3f8ee2f6 /public_key.go | |
parent | 2f9126dc6a2eab32316ec90e21688d31159f9e80 (diff) |
redesign cli
This is a major rebuilding of the CLI. The library part is split out
into pkilib and the cli handles only the communication with the user,
I/O and the library.
The API will still look the same, but the code should be much better to
grasp. Instead of repeating everything, more will be grouped together
and reused.
Diffstat (limited to 'public_key.go')
-rw-r--r-- | public_key.go | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/public_key.go b/public_key.go deleted file mode 100644 index cbafc49..0000000 --- a/public_key.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -// create a public key from a private key - -import ( - "crypto/x509" - "encoding/pem" - "flag" - "fmt" - "io" - "os" -) - -type ( - PublicKeyFlags struct { - PrivateKeyPath string - Output string - - output_stream io.WriteCloser // the actual stream to the output - } -) - -func create_public_key() { - var err error - flags := parse_public_key_flags() - flags.output_stream, err = open_output_stream(flags.Output) - if err != nil { - crash_with_help(2, fmt.Sprintf("Error when creating file %s: %s", flags.Output, err)) - } - defer flags.output_stream.Close() - - priv_key := load_private_key(flags.PrivateKeyPath) - marshal, err := x509.MarshalPKIXPublicKey(priv_key.Public()) - if err != nil { - crash_with_help(2, fmt.Sprintf("Problems marshalling the public key: %s", err)) - } - - block := &pem.Block{Type: TypeLabelPubKey, Bytes: marshal} - pem.Encode(flags.output_stream, block) -} - -func parse_public_key_flags() PublicKeyFlags { - flags := PublicKeyFlags{} - fs := flag.NewFlagSet("create-public", flag.ExitOnError) - fs.StringVar(&flags.PrivateKeyPath, "private-key", "", "path to the private key file") - fs.StringVar(&flags.Output, "output", "STDOUT", "path where the generated public key should be stored") - fs.Parse(os.Args[2:]) - - return flags -} |