From d856337a7dbe4bbab82aaf735c859d203ba89a40 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 25 Dec 2015 12:18:39 +0100 Subject: Add save and load cert --- crypto.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crypto.go') 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) +} -- cgit v1.2.3