tempfork/x509: store certs for iOS compressed in binary, parse lazily

This commit is contained in:
Brad Fitzpatrick
2020-04-25 08:52:53 -07:00
parent 8fd8fc9c7d
commit 28c632c97b
7 changed files with 4533 additions and 4409 deletions
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2020 Tailscale Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !x509omitbundledroots
package x509
import (
"compress/gzip"
"io/ioutil"
"strings"
"sync"
)
func certUncompressor(zcertBytes string) func() (*Certificate, error) {
var once sync.Once
var c *Certificate
var err error
return func() (*Certificate, error) {
once.Do(func() {
var certBytes []byte
var zr *gzip.Reader
zr, err = gzip.NewReader(strings.NewReader(zcertBytes))
if err != nil {
return
}
certBytes, err = ioutil.ReadAll(zr)
if err != nil {
return
}
c, err = ParseCertificate(certBytes)
})
return c, err
}
}