})
}
+ if t.iOS() && !t.compileOnly {
+ t.tests = append(t.tests, distTest{
+ name: "x509omitbundledroots",
+ heading: "crypto/x509 without bundled roots",
+ fn: func(dt *distTest) error {
+ t.addCmd(dt, "src", t.goTest(), t.timeout(300), "-tags=x509omitbundledroots", "-run=OmitBundledRoots", "crypto/x509")
+ return nil
+ },
+ })
+ }
+
if t.race {
return
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build !x509omitbundledroots
+
package x509
func loadSystemRoots() (*CertPool, error) {
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build !x509omitbundledroots
+
package x509
func loadSystemRoots() (*CertPool, error) {
--- /dev/null
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin,arm64,x509omitbundledroots
+
+// This file provides the loadSystemRoots func when the
+// "x509omitbundledroots" build tag has disabled bundling a copy,
+// which currently on happens on darwin/arm64 (root_darwin_arm64.go).
+// This then saves 256 KiB of binary size and another 560 KiB of
+// runtime memory size retaining the parsed roots forever. Constrained
+// environments can construct minimal x509 root CertPools on the fly
+// in the crypto/tls.Config.VerifyPeerCertificate hook.
+
+package x509
+
+import "errors"
+
+func loadSystemRoots() (*CertPool, error) {
+ return nil, errors.New("x509: system root bundling disabled")
+}
--- /dev/null
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin,arm64,x509omitbundledroots
+
+package x509
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestOmitBundledRoots(t *testing.T) {
+ cp, err := loadSystemRoots()
+ if err == nil {
+ t.Fatalf("loadSystemRoots = (pool %p, error %v); want non-nil error", cp, err)
+ }
+ if !strings.Contains(err.Error(), "root bundling disabled") {
+ t.Errorf("unexpected error doesn't mention bundling: %v", err)
+ }
+}