func (id ID) MemberOf(td TrustDomain) bool {
	return id.td == td
}
MemberOf returns true if the SPIFFE ID is a member of the given trust domain.
package spiffeid
import (
	"net/url"
	"path"
	"strings"
	"github.com/zeebo/errs"
)
var idErr = errs.Class("spiffeid")
type ID struct {
	td   TrustDomain
	path string
}
func New(trustDomain string, segments ...string) (ID, error) {
	td, err := TrustDomainFromString(trustDomain)
	if err != nil {
		return ID{}, err
	}
	return ID{
		td:   td,
		path: normalizePath(path.Join(segments...)),
	}, nil
}
func Must(trustDomain string, segments ...string) ID {
	id, err := New(trustDomain, segments...)
	if err != nil {
		panic(err)
	}
	return id
}
func Join(trustDomain string, segments ...string) (string, error) {
	id, err := New(trustDomain, segments...)
	if err != nil {
		return "", err
	}
	return id.String(), nil
}
func MustJoin(trustDomain string, segments ...string) string {
	idstr, err := Join(trustDomain, segments...)
	if err != nil {
		panic(err)
	}
	return idstr
}
func FromString(s string) (ID, error) {
	uri, err := url.Parse(s)
	if err != nil {
		return ID{}, idErr.New("unable to parse: %w", err)
	}
	return FromURI(uri)
}
func FromURI(uri *url.URL) (ID, error) {
	switch {
	case uri == nil:
		return ID{}, idErr.New("ID is nil")
	case *uri == (url.URL{}):
		return ID{}, idErr.New("ID is empty")
	case strings.ToLower(uri.Scheme) != "spiffe":
		return ID{}, idErr.New("invalid scheme")
	case uri.User != nil:
		return ID{}, idErr.New("user info is not allowed")
	case uri.Host == "":
		return ID{}, idErr.New("trust domain is empty")
	case uri.Port() != "":
		return ID{}, idErr.New("port is not allowed")
	case strings.Contains(uri.Host, ":"):
		return ID{}, idErr.New("colon is not allowed in trust domain")
	case uri.Fragment != "":
		return ID{}, idErr.New("fragment is not allowed")
	case uri.RawQuery != "":
		return ID{}, idErr.New("query is not allowed")
	}
	return ID{
		td:   TrustDomain{name: normalizeTrustDomain(uri.Host)},
		path: uri.Path,
	}, nil
}
func RequireFromString(s string) ID {
	id, err := FromString(s)
	if err != nil {
		panic(err)
	}
	return id
}
func RequireFromURI(uri *url.URL) ID {
	id, err := FromURI(uri)
	if err != nil {
		panic(err)
	}
	return id
}
func (id ID) TrustDomain() TrustDomain {
	return id.td
}