aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crypto.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto.go b/crypto.go
index bb1dd6a..e005562 100644
--- a/crypto.go
+++ b/crypto.go
@@ -59,3 +59,20 @@ func Thumb(token string, key crypto.PublicKey) (string, error) {
}
return token + "." + base64.RawURLEncoding.EncodeToString(thumb), nil
}
+
+func SaveCert(w io.Writer, der []byte) error {
+ block := &pem.Block{
+ Type: "CERTIFICATE",
+ Bytes: der,
+ }
+ return pem.Encode(w, block)
+}
+
+func LoadCert(r io.Reader) ([]*x509.Certificate, error) {
+ der, err := ioutil.ReadAll(r)
+ if err != nil {
+ return nil, err
+ }
+ block, _ := pem.Decode(der)
+ return x509.ParseCertificates(block.Bytes)
+}