certificates/acme/certificate.go

28 lines
621 B
Go
Raw Normal View History

2019-05-27 00:41:10 +00:00
package acme
import (
"crypto/x509"
"encoding/pem"
)
2021-02-28 18:09:06 +00:00
// Certificate options with which to create and store a cert object.
type Certificate struct {
ID string
2019-05-27 00:41:10 +00:00
AccountID string
OrderID string
Leaf *x509.Certificate
Intermediates []*x509.Certificate
}
2021-02-28 18:09:06 +00:00
// ToACME encodes the entire X509 chain into a PEM list.
2021-03-05 07:10:46 +00:00
func (cert *Certificate) ToACME() ([]byte, error) {
2021-02-28 18:09:06 +00:00
var ret []byte
for _, c := range append([]*x509.Certificate{cert.Leaf}, cert.Intermediates...) {
ret = append(ret, pem.EncodeToMemory(&pem.Block{
2019-05-27 00:41:10 +00:00
Type: "CERTIFICATE",
2021-02-28 18:09:06 +00:00
Bytes: c.Raw,
2019-05-27 00:41:10 +00:00
})...)
}
2021-02-28 18:09:06 +00:00
return ret, nil
2019-05-27 00:41:10 +00:00
}