certificates/acme/certificate.go

28 lines
621 B
Go
Raw Normal View History

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