File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
"crypto/x509"
21
21
"crypto/x509/pkix"
22
22
"encoding/pem"
23
+ "errors"
23
24
"fmt"
24
25
"math"
25
26
"math/big"
@@ -54,6 +55,24 @@ func encodeCertificatePEM(cert *x509.Certificate) []byte {
54
55
})
55
56
}
56
57
58
+ // parsePEMEncodedCert parses a certificate from the given pemdata
59
+ func parsePEMEncodedCert (pemdata []byte ) (* x509.Certificate , error ) {
60
+ decoded , _ := pem .Decode (pemdata )
61
+ if decoded == nil {
62
+ return nil , errors .New ("no PEM data found" )
63
+ }
64
+ return x509 .ParseCertificate (decoded .Bytes )
65
+ }
66
+
67
+ // parsePEMEncodedPrivateKey parses a private key from given pemdata
68
+ func parsePEMEncodedPrivateKey (pemdata []byte ) (* rsa.PrivateKey , error ) {
69
+ decoded , _ := pem .Decode (pemdata )
70
+ if decoded == nil {
71
+ return nil , errors .New ("no PEM data found" )
72
+ }
73
+ return x509 .ParsePKCS1PrivateKey (decoded .Bytes )
74
+ }
75
+
57
76
// newSelfSignedCACertificate returns a self-signed CA certificate based on given configuration and private key.
58
77
// The certificate has one-year lease.
59
78
func newSelfSignedCACertificate (key * rsa.PrivateKey ) (* x509.Certificate , error ) {
You can’t perform that action at this time.
0 commit comments