diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2018-04-19 08:33:11 +0200 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2018-04-19 08:33:11 +0200 |
commit | f3910624b8314145a8cb026e55112a93d672fc3f (patch) | |
tree | 1de00b10be7d2be04c5c93363ae227f24851f179 /load_private_key.go | |
parent | 083e8c2ce4ee8ed250d1e38bd115717733f0a324 (diff) |
add more error checks
There are still some cases where the input is not correctly checked, but
it is moving forward.
Diffstat (limited to 'load_private_key.go')
-rw-r--r-- | load_private_key.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/load_private_key.go b/load_private_key.go index 4678862..e2a590e 100644 --- a/load_private_key.go +++ b/load_private_key.go @@ -27,27 +27,24 @@ func loadPrivateKey(path string) (pki.PrivateKey, error) { pems, err := parseFile(file) if err != nil { - return nil, err + return nil, fmt.Errorf("could not load private key: %s", err) } if len(pems) > 1 { return nil, fmt.Errorf("more than one object in file") } - var pk pki.PrivateKey for key, parts := range pems { if len(parts) > 1 { return nil, fmt.Errorf("more than one object found") } switch key { case pki.PemLabelRsa: - pk, err = pki.LoadPrivateKeyRsa(parts[0]) + return pki.LoadPrivateKeyRsa(parts[0]) case pki.PemLabelEd25519: - pk, err = pki.LoadPrivateKeyEd25519(parts[0]) + return pki.LoadPrivateKeyEd25519(parts[0]) case pki.PemLabelEcdsa: - pk, err = pki.LoadPrivateKeyEcdsa(parts[0]) - default: - return nil, fmt.Errorf("unknown private key format %s", key) + return pki.LoadPrivateKeyEcdsa(parts[0]) } } - return pk, err + return nil, fmt.Errorf("no private key found in file '%s'", path) } |