Skip to content

Commit 09d47c4

Browse files
committed
fix ReadCertPool function
* document acceptable input * don't fail if input is not either a file or directory * trim space in comma delineated file list
1 parent a633fd7 commit 09d47c4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crypto/x509util/crt.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ import (
1313
)
1414

1515
// ReadCertPool loads a certificate pool from disk.
16+
// *path*: a file, a directory, or a comma-separated list of files.
1617
func ReadCertPool(path string) (*realx509.CertPool, error) {
1718
info, err := os.Stat(path)
18-
if err != nil {
19-
return nil, errors.WithStack(err)
19+
if err != nil && !os.IsNotExist(err) {
20+
return nil, errors.Wrapf(err, "os.Stat %s failed", path)
2021
}
2122

2223
var (
2324
files []string
2425
pool = realx509.NewCertPool()
2526
)
26-
if info.IsDir() {
27+
if info != nil && info.IsDir() {
2728
finfos, err := ioutil.ReadDir(path)
2829
if err != nil {
2930
return nil, errs.FileError(err, path)
@@ -33,6 +34,9 @@ func ReadCertPool(path string) (*realx509.CertPool, error) {
3334
}
3435
} else {
3536
files = strings.Split(path, ",")
37+
for i := range files {
38+
files[i] = strings.TrimSpace(files[i])
39+
}
3640
}
3741

3842
var pems []byte

0 commit comments

Comments
 (0)