From 2b74dbb334192eb25ebd9de2d1273692797ec558 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 16 Mar 2015 17:10:46 +0100 Subject: implement marshal pem interface for certificates --- certificate.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/certificate.go b/certificate.go index e118833..b6fa252 100644 --- a/certificate.go +++ b/certificate.go @@ -11,7 +11,10 @@ import ( "time" ) -const PemLabelCertificateRequest = "CERTIFICATE REQUEST" +const ( + PemLabelCertificateRequest = "CERTIFICATE REQUEST" + PemLabelCertificate = "CERTIFICATE" +) type ( CertificateData struct { @@ -111,6 +114,12 @@ func LoadCertificate(raw []byte) (*Certificate, error) { return (*Certificate)(cert), nil } +// marshal the certificate to a pem block +func (c *Certificate) MarshalPem() (marshalledPemBlock, error) { + block := &pem.Block{Type: PemLabelCertificate, Bytes: c.Raw} + return pem.EncodeToMemory(block), nil +} + func (co *CertificateOptions) Valid() error { if co.SerialNumber == nil { return fmt.Errorf("No serial number set!") } return nil -- cgit v1.2.3-70-g09d2