diff options
author | Gibheer <gibheer+git@zero-knowledge.org> | 2017-05-12 15:27:44 +0200 |
---|---|---|
committer | Gibheer <gibheer+git@zero-knowledge.org> | 2017-05-12 15:27:44 +0200 |
commit | b6c44317f540dac8763e720767b0e73940a0b6c5 (patch) | |
tree | fac6e911056ba12da589dac4ad1f32aa63430f78 /ecdsa.go | |
parent | fd88bca2872e589b451cde3767dbc59d82bd1c83 (diff) |
add proper pem interface
This should finally resolve the completely broken and wrong API to get a
pem representation of a resource.
Diffstat (limited to 'ecdsa.go')
-rw-r--r-- | ecdsa.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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) |