diff options
author | Gibheer <gibheer@gmail.com> | 2015-02-20 10:45:42 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2015-02-20 10:45:42 +0100 |
commit | 075865c417c387783d37a6705d66034f2fd9ff4a (patch) | |
tree | 106a183e55b732d84bd9532751587e6ae978173f /private_key.go | |
parent | 1c621c063c26205e23af7bc7e3da4b5064856d4c (diff) |
add verification of messages
This commit adds back the possibility to verify a message through a
public key and a signature. It works a little bit different than before
as it always prints the base64 version, but it makes it easier to use.
Diffstat (limited to 'private_key.go')
-rw-r--r-- | private_key.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/private_key.go b/private_key.go index 3e6aee3..0591e18 100644 --- a/private_key.go +++ b/private_key.go @@ -5,25 +5,22 @@ import ( "github.com/gibheer/pki" ) -const ( - TypeLabelRSA = "RSA PRIVATE KEY" - TypeLabelECDSA = "EC PRIVATE KEY" -) - var ( ErrNoPKFound = errors.New("no private key found") + ErrNoPUFound = errors.New("no public key found") + ErrUnknownFormat = errors.New("key is an unknown format") ) // Read the private key from the path and try to figure out which type of key it // might be. func ReadPrivateKeyFile(path string) (pki.PrivateKey, error) { - raw_pk, err := readSectionFromFile(path, TypeLabelECDSA) + raw_pk, err := readSectionFromFile(path, pki.PemLabelEcdsa) if err == nil { pk, err := pki.LoadPrivateKeyEcdsa(raw_pk) if err != nil { return nil, err } return pk, nil } - raw_pk, err = readSectionFromFile(path, TypeLabelRSA) + raw_pk, err = readSectionFromFile(path, pki.PemLabelRsa) if err == nil { pk, err := pki.LoadPrivateKeyRsa(raw_pk) if err != nil { return nil, err } @@ -31,3 +28,16 @@ func ReadPrivateKeyFile(path string) (pki.PrivateKey, error) { } return nil, ErrNoPKFound } + +// read the public key and try to figure out what kind of key it might be +func ReadPublicKeyFile(path string) (pki.PublicKey, error) { + raw_pu, err := readSectionFromFile(path, pki.PemLabelPublic) + if err != nil { return nil, ErrNoPUFound } + + var public pki.PublicKey + public, err = pki.LoadPublicKeyEcdsa(raw_pu) + if err == nil { return public, nil } + public, err = pki.LoadPublicKeyRsa(raw_pu) + if err == nil { return public, nil } + return nil, ErrUnknownFormat +} |