Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37cd1e7

Browse filesBrowse files
committed
Factored function to encode certs as PEM
1 parent dc68681 commit 37cd1e7
Copy full SHA for 37cd1e7

File tree

Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed

‎certificates/certutils.go

Copy file name to clipboardExpand all lines: certificates/certutils.go
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,12 @@ func LoadCertificatesFromFile(certificateFile *paths.Path) ([]*x509.Certificate,
9696
return nil, fmt.Errorf("cert format %s not supported, please use .pem or .cer", certificateFile.Ext())
9797
}
9898
}
99+
100+
// EncodeCertificateAsPEM returns the PEM encoding of the given certificate
101+
func EncodeCertificateAsPEM(cert *x509.Certificate) []byte {
102+
pemBlock := &pem.Block{
103+
Type: "CERTIFICATE",
104+
Bytes: cert.Raw,
105+
}
106+
return pem.EncodeToMemory(pemBlock)
107+
}

‎flasher/nina.go

Copy file name to clipboardExpand all lines: flasher/nina.go
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"bytes"
2323
"crypto/md5"
2424
"encoding/binary"
25-
"encoding/pem"
2625
"fmt"
2726
"io"
2827
"time"
@@ -106,7 +105,7 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
106105
return err
107106
}
108107
for _, cert := range certs {
109-
data := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
108+
data := certificates.EncodeCertificateAsPEM(cert)
110109
certificatesData = append(certificatesData, data...)
111110
}
112111
}
@@ -118,7 +117,7 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [
118117
if err != nil {
119118
return err
120119
}
121-
data := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: rootCertificate.Raw})
120+
data := certificates.EncodeCertificateAsPEM(rootCertificate)
122121
certificatesData = append(certificatesData, data...)
123122
}
124123

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.