Documentation ¶
Overview ¶
Package certpool provides an X.509 certificates store
Index ¶
- Constants
- Variables
- type CertPool
- func (s *CertPool) AddCert(cert *x509.Certificate) bool
- func (s *CertPool) Clone() x509utils.CertPool
- func (s *CertPool) Copy(out *CertPool, cond func(*x509.Certificate) bool) *CertPool
- func (s *CertPool) Count() int
- func (s *CertPool) Delete(ctx context.Context, name string) error
- func (s *CertPool) DeleteCert(ctx context.Context, cert *x509.Certificate) error
- func (s *CertPool) Export() *x509.CertPool
- func (s *CertPool) ForEach(ctx context.Context, fn func(context.Context, *x509.Certificate) bool)
- func (s *CertPool) Get(ctx context.Context, name string) (*x509.Certificate, error)
- func (s *CertPool) Import(ctx context.Context, src x509utils.CertPool) (int, error)
- func (s *CertPool) ImportPEM(ctx context.Context, b []byte) (int, error)
- func (s *CertPool) IsCA() bool
- func (s *CertPool) IsZero() bool
- func (s *CertPool) Put(ctx context.Context, name string, cert *x509.Certificate) error
- func (s *CertPool) Reset() error
- type CertSet
- type Hash
Constants ¶
const (
// HashSize is the number of bytes of HashCert's output
HashSize = 32
)
Variables ¶
var ( // ErrNoCertificatesFound indicates we didn't find any certificate. ErrNoCertificatesFound = core.Wrap(core.ErrNotExists, "no certificates found") )
var ( // SystemCAOnly indicates if SystemCertPool show ignore // non-CA certificates. // // Changing this after SystemCertPool() has been called // has no effect. SystemCAOnly bool )
Functions ¶
This section is empty.
Types ¶
type CertPool ¶
type CertPool struct {
// contains filtered or unexported fields
}
CertPool is a collection of x.509 Certificates.
func NewFromEnv ¶
NewFromEnv uses os.LookupEnv and the given variable name to create a CertPool using NewFromStrings.
func NewFromEnvFn ¶
NewFromEnvFn is like NewFromEnv but allows the user to provide a function to access the environment.
func NewFromStrings ¶
NewFromStrings creates a CertPool using certificates in a string. it could be PEM content, a PEM file, or a directory containing PEM files. The populated CertPool will be returned even if errors were encountered. A core.CompoundError will be returned if there were errors.
func NewSystemCertPool ¶
NewSystemCertPool returns a CertPool populated with all system valid certificates and an aggregation of errors.
func SystemCertPool ¶
SystemCertPool returns a Pool populated with the system's valid certificates.
func (*CertPool) AddCert ¶
func (s *CertPool) AddCert(cert *x509.Certificate) bool
AddCert adds a certificate to the store if it wasn't known already.
func (*CertPool) Copy ¶
Copy creates a copy of the CertPool store, optionally receiving the destination and a condition checker.
func (*CertPool) Delete ¶
Delete remove from the store all certificates associated to the given name
func (*CertPool) DeleteCert ¶
DeleteCert removes a certificate, by raw DER hash, from the store.
func (*CertPool) Export ¶
Export assembles a x509.CertPool with all the certificates contained in the store.
func (*CertPool) ForEach ¶
ForEach calls a function for each certificate in the store until the context is cancelled or the function returns false.
type CertSet ¶ added in v0.3.1
type CertSet struct { set.Set[*x509.Certificate, Hash, *x509.Certificate] }
CertSet keeps a thread-safe set of unique [x509.Certificate]s.
func MustCertSet ¶ added in v0.3.1
func MustCertSet(certs ...*x509.Certificate) *CertSet
MustCertSet is like NewCertSet but panics on errors.
func NewCertSet ¶ added in v0.3.1
func NewCertSet(certs ...*x509.Certificate) (*CertSet, error)
NewCertSet creates a CertSet optionally taking its initial content as argument.
func (*CertSet) Copy ¶ added in v0.4.0
Copy copies all certificates satisfying the optional condition to the destination unless they are already there. If a destination isn't provided one will be created.
func (*CertSet) GetByKey ¶ added in v0.4.2
func (cs *CertSet) GetByKey(pub crypto.PublicKey) []*x509.Certificate
GetByKey returns all certificates in the CertSet matching the given public key.
func (*CertSet) GetByPrivateKey ¶ added in v0.4.2
func (cs *CertSet) GetByPrivateKey(key crypto.PrivateKey) []*x509.Certificate
GetByPrivateKey returns all certificates in the CertSet matching the given private key.
type Hash ¶
Hash is a blake3.Sum256 representation of a DER encoded certificate
func HashCert ¶
func HashCert(cert *x509.Certificate) (Hash, bool)
HashCert produces a blake3 digest of the DER representation of a Certificate
func HashSubject ¶
func HashSubject(cert *x509.Certificate) (Hash, bool)
HashSubject produces a blake3 digest of the raw subject of the Certificate
func HashSubjectPublicKey ¶
func HashSubjectPublicKey(cert *x509.Certificate) (Hash, bool)
HashSubjectPublicKey produces a blake3 digest of the PublicKey of the Certificate