github.com/blend/go-sdk@v1.20220411.3/certutil/create_cert_pool.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package certutil
     9  
    10  import (
    11  	"crypto/x509"
    12  
    13  	"github.com/blend/go-sdk/ex"
    14  )
    15  
    16  // CreateCertPool extends an empty pool with a given set of certs.
    17  func CreateCertPool(keyPairs ...KeyPair) (*x509.CertPool, error) {
    18  	pool := x509.NewCertPool()
    19  	var err error
    20  	var contents []byte
    21  	for _, keyPair := range keyPairs {
    22  		contents, err = keyPair.CertBytes()
    23  		if err != nil {
    24  			return nil, err
    25  		}
    26  		if ok := pool.AppendCertsFromPEM(contents); !ok {
    27  			return nil, ex.New(ErrInvalidCertPEM)
    28  		}
    29  	}
    30  	return pool, nil
    31  }