func (s *Set) GetX509BundleForTrustDomain(trustDomain spiffeid.TrustDomain) (*x509bundle.Bundle, error) {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	bundle, ok := s.bundles[trustDomain]
	if !ok {
		return nil, spiffebundleErr.New("no X.509 bundle for trust domain %q", trustDomain)
	}
	return bundle.X509Bundle(), nil
}
GetX509BundleForTrustDomain returns the X.509 bundle for the given trust
domain. It implements the x509bundle.Source interface.
package spiffebundle
import (
	"sort"
	"sync"
	"github.com/spiffe/go-spiffe/v2/bundle/jwtbundle"
	"github.com/spiffe/go-spiffe/v2/bundle/x509bundle"
	"github.com/spiffe/go-spiffe/v2/spiffeid"
)
type Set struct {
	mtx     sync.RWMutex
	bundles map[spiffeid.TrustDomain]*Bundle
}
func NewSet(bundles ...*Bundle) *Set {
	bundlesMap := make(map[spiffeid.TrustDomain]*Bundle)
	for _, b := range bundles {
		if b != nil {
			bundlesMap[b.trustDomain] = b
		}
	}
	return &Set{
		bundles: bundlesMap,
	}
}
func (s *Set) Add(bundle *Bundle) {
	s.mtx.Lock()
	defer s.mtx.Unlock()
	if bundle != nil {
		s.bundles[bundle.trustDomain] = bundle
	}
}
func (s *Set) Remove(trustDomain spiffeid.TrustDomain) {
	s.mtx.Lock()
	defer s.mtx.Unlock()
	delete(s.bundles, trustDomain)
}
func (s *Set) Has(trustDomain spiffeid.TrustDomain) bool {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	_, ok := s.bundles[trustDomain]
	return ok
}
func (s *Set) Get(trustDomain spiffeid.TrustDomain) (*Bundle, bool) {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	bundle, ok := s.bundles[trustDomain]
	return bundle, ok
}
func (s *Set) Bundles() []*Bundle {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	out := make([]*Bundle, 0, len(s.bundles))
	for _, bundle := range s.bundles {
		out = append(out, bundle)
	}
	sort.Slice(out, func(a, b int) bool {
		return out[a].TrustDomain().Compare(out[b].TrustDomain()) < 0
	})
	return out
}
func (s *Set) Len() int {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	return len(s.bundles)
}
func (s *Set) GetBundleForTrustDomain(trustDomain spiffeid.TrustDomain) (*Bundle, error) {
	s.mtx.RLock()
	defer s.mtx.RUnlock()
	bundle, ok := s.bundles[trustDomain]
	if !ok {
		return nil, spiffebundleErr.New("no SPIFFE bundle for trust domain %q", trustDomain)
	}
	return bundle, nil
}