From e95929ed2641bf6548aada92d9d17a3441f19e2b Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 12 May 2017 22:19:25 +0200 Subject: Add ToPem() to public keys This was missing before from all public keys. --- rsa.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'rsa.go') diff --git a/rsa.go b/rsa.go index 7d575cb..b4024ac 100644 --- a/rsa.go +++ b/rsa.go @@ -86,13 +86,21 @@ func LoadPublicKeyRsa(raw []byte) (*RsaPublicKey, error) { return pub, nil } +// ToPem returns the pem encoded public key. +func (pu *RsaPublicKey) ToPem() (pem.Block, error) { + asn1, err := x509.MarshalPKIXPublicKey(pu.public_key) + if err != nil { + return pem.Block{}, err + } + return pem.Block{Type: PemLabelPublic, Bytes: asn1}, nil +} + // marshal a rsa public key into pem format func (pu *RsaPublicKey) MarshalPem() (io.WriterTo, error) { - asn1, err := x509.MarshalPKIXPublicKey(pu.public_key) + pem_block, err := pu.ToPem() if err != nil { return nil, err } - pem_block := pem.Block{Type: PemLabelPublic, Bytes: asn1} return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil } -- cgit v1.2.3-70-g09d2