From b6c44317f540dac8763e720767b0e73940a0b6c5 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 12 May 2017 15:27:44 +0200 Subject: add proper pem interface This should finally resolve the completely broken and wrong API to get a pem representation of a resource. --- ecdsa.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ecdsa.go') diff --git a/ecdsa.go b/ecdsa.go index 66b73f5..8bf432d 100644 --- a/ecdsa.go +++ b/ecdsa.go @@ -78,14 +78,22 @@ func (pr EcdsaPrivateKey) PrivateKey() crypto.PrivateKey { // This function implements the Pemmer interface to marshal the private key // into a pem block. func (pr EcdsaPrivateKey) MarshalPem() (io.WriterTo, error) { - asn1, err := x509.MarshalECPrivateKey(pr.private_key) + pem_block, err := pr.ToPem() if err != nil { return nil, err } - pem_block := pem.Block{Type: PemLabelEcdsa, Bytes: asn1} return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil } +// This function implements ToPem to return the raw pem block. +func (pr EcdsaPrivateKey) ToPem() (pem.Block, error) { + asn1, err := x509.MarshalECPrivateKey(pr.private_key) + if err != nil { + return pem.Block{}, err + } + return pem.Block{Type: PemLabelEcdsa, Bytes: asn1}, nil +} + // This functoin loads an ecdsa public key from the asn.1 representation. func LoadPublicKeyEcdsa(raw []byte) (*EcdsaPublicKey, error) { raw_pub, err := x509.ParsePKIXPublicKey(raw) -- cgit v1.2.3-70-g09d2