/
certchain.go
42 lines (38 loc) · 961 Bytes
/
certchain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package credentials
import (
"os"
)
const (
// RootCertFilename is the filename that holds the root certificate.
RootCertFilename = "ca.crt"
// IssuerCertFilename is the filename that holds the issuer certificate.
IssuerCertFilename = "issuer.crt"
// IssuerKeyFilename is the filename that holds the issuer key.
IssuerKeyFilename = "issuer.key"
)
// CertChain holds the certificate trust chain PEM values.
type CertChain struct {
RootCA []byte
Cert []byte
Key []byte
}
// LoadFromDisk retruns a CertChain from a given directory.
func LoadFromDisk(rootCertPath, issuerCertPath, issuerKeyPath string) (*CertChain, error) {
rootCert, err := os.ReadFile(rootCertPath)
if err != nil {
return nil, err
}
cert, err := os.ReadFile(issuerCertPath)
if err != nil {
return nil, err
}
key, err := os.ReadFile(issuerKeyPath)
if err != nil {
return nil, err
}
return &CertChain{
RootCA: rootCert,
Cert: cert,
Key: key,
}, nil
}