Get pem data easier

This commit is contained in:
Melon 2022-03-13 14:44:13 +00:00
parent 4d057cdb31
commit 80469dfbd1
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6

16
cert.go
View File

@ -17,9 +17,10 @@ type CertGen struct {
certPem, keyPem []byte certPem, keyPem []byte
} }
func (ca *CertGen) GetTlsLeaf() tls.Certificate { func (ca *CertGen) GetTlsLeaf() tls.Certificate { return ca.tlsCert }
return ca.tlsCert
} func (ca *CertGen) GetCertPem() []byte { return ca.certPem }
func (ca *CertGen) GetKeyPem() []byte { return ca.keyPem }
func (ca *CertGen) generatePem() error { func (ca *CertGen) generatePem() error {
a := new(bytes.Buffer) a := new(bytes.Buffer)
@ -58,11 +59,16 @@ func LoadCertGen(certBytes, keyBytes []byte) (*CertGen, error) {
return nil, err return nil, err
} }
leaf := TlsLeaf(&pair) leaf := TlsLeaf(&pair)
return &CertGen{ gen := &CertGen{
tlsCert: pair, tlsCert: pair,
cert: leaf, cert: leaf,
key: pair.PrivateKey, key: pair.PrivateKey,
certBytes: certBytes, certBytes: certBytes,
keyBytes: keyBytes, keyBytes: keyBytes,
}, nil }
err = gen.generatePem()
if err != nil {
return nil, err
}
return gen, nil
} }