diff options
-rw-r--r-- | crypto.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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) +} |