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 /certificate.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 'certificate.go')
-rw-r--r-- | certificate.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/certificate.go b/certificate.go index 3adb530..b90e9fa 100644 --- a/certificate.go +++ b/certificate.go @@ -81,10 +81,18 @@ func LoadCertificateSignRequest(raw []byte) (*CertificateRequest, error) { return (*CertificateRequest)(csr), nil } +// ToPem returns a pem.Block representing the CertificateRequest. +func (c *CertificateRequest) ToPem() (pem.Block, error) { + return pem.Block{Type: PemLabelCertificateRequest, Bytes: c.Raw}, nil +} + // Return the certificate sign request as a pem block. func (c *CertificateRequest) MarshalPem() (io.WriterTo, error) { - block := &pem.Block{Type: PemLabelCertificateRequest, Bytes: c.Raw} - return marshalledPemBlock(pem.EncodeToMemory(block)), nil + if block, err := c.ToPem(); err != nil { + return nil, err + } else { + return marshalledPemBlock(pem.EncodeToMemory(&block)), nil + } } // Convert the certificate sign request to a certificate using the private key @@ -152,8 +160,16 @@ func LoadCertificate(raw []byte) (*Certificate, error) { // marshal the certificate to a pem block func (c *Certificate) MarshalPem() (io.WriterTo, error) { - block := &pem.Block{Type: PemLabelCertificate, Bytes: c.Raw} - return marshalledPemBlock(pem.EncodeToMemory(block)), nil + if block, err := c.ToPem(); err != nil { + return nil, err + } else { + return marshalledPemBlock(pem.EncodeToMemory(&block)), nil + } +} + +// ToPem returns the pem block of the certificate. +func (c *Certificate) ToPem() (pem.Block, error) { + return pem.Block{Type: PemLabelCertificate, Bytes: c.Raw}, nil } // Check if the certificate options have the required fields set. |