diff options
author | Gibheer <gibheer@gmail.com> | 2015-02-19 21:48:08 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2015-02-19 21:48:08 +0100 |
commit | 80db488cbdbd7a35f61526f8581d806849703298 (patch) | |
tree | fdac06b68003bdd94a579cebaf03e8c39e2f8972 /ecdsa.go | |
parent | 639a5379e9abf4a3f0d88464d1a229f8d5df14ae (diff) |
add public key loader
This adds a way to restore a public key from any data source.
Diffstat (limited to 'ecdsa.go')
-rw-r--r-- | ecdsa.go | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -75,6 +75,16 @@ func (pr EcdsaPrivateKey) MarshalPem() (marshalledPemBlock, error) { return pem.EncodeToMemory(&pem_block), nil } +// load an ecdsa public key +func LoadPublicKeyEcdsa(raw []byte) (*EcdsaPublicKey, error) { + raw_pub, err := x509.ParsePKIXPublicKey(raw) + if err != nil { return nil, err } + + pub, ok := raw_pub.(*ecdsa.PublicKey) + if !ok { return nil, errors.New("Not an ecdsa key!") } + return &EcdsaPublicKey{pub}, nil +} + // marshal the public key to a pem block func (pu *EcdsaPublicKey) MarshalPem() (marshalledPemBlock, error) { asn1, err := x509.MarshalPKIXPublicKey(pu.public_key) |