From 80db488cbdbd7a35f61526f8581d806849703298 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 19 Feb 2015 21:48:08 +0100 Subject: add public key loader This adds a way to restore a public key from any data source. --- ecdsa.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ecdsa.go') diff --git a/ecdsa.go b/ecdsa.go index 6754ee4..42c5cf1 100644 --- a/ecdsa.go +++ b/ecdsa.go @@ -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) -- cgit v1.2.3-70-g09d2