func (extractor *tlsStaticClientIDExtractor) ExtractClientID(certificate *x509.Certificate) ([]byte, error) {
	return extractor.clientID, nil
}
ExtractClientID returns configured static clientID
package network
import (
	"crypto/sha512"
	"crypto/x509"
	"encoding/hex"
	"errors"
	log "github.com/sirupsen/logrus"
	"hash"
)
const (
	IdentifierExtractorTypeDistinguishedName = "distinguished_name"
	IdentifierExtractorTypeSerialNumber      = "serial_number"
)
var IdentifierExtractorTypesList = []string{
	IdentifierExtractorTypeDistinguishedName,
	IdentifierExtractorTypeSerialNumber,
}
var ErrInvalidIdentifierExtractorType = errors.New("invalid identifier extractor type")
func NewIdentifierExtractorByType(extractorType string) (CertificateIdentifierExtractor, error) {
	switch extractorType {
	case IdentifierExtractorTypeDistinguishedName:
		return DistinguishedNameExtractor{}, nil
	case IdentifierExtractorTypeSerialNumber:
		return SerialNumberExtractor{}, nil
	default:
		return nil, ErrInvalidIdentifierExtractorType
	}
}
type CertificateIdentifierExtractor interface {
	GetCertificateIdentifier(certificate *x509.Certificate) ([]byte, error)
}
type DistinguishedNameExtractor struct{}
func (e DistinguishedNameExtractor) GetCertificateIdentifier(certificate *x509.Certificate) ([]byte, error) {
	if certificate == nil {
		return nil, ErrNoPeerCertificate
	}
	id := []byte(certificate.Subject.String())
	if len(id) == 0 {
		return nil, ErrEmptyIdentifier
	}
	return id, nil
}
type SerialNumberExtractor struct{}
func (e SerialNumberExtractor) GetCertificateIdentifier(certificate *x509.Certificate) ([]byte, error) {
	if certificate == nil {
		return nil, ErrNoPeerCertificate
	}
	if certificate.SerialNumber == nil {
		return nil, ErrEmptyIdentifier
	}
	return certificate.SerialNumber.Bytes(), nil
}
var ErrEmptyIdentifier = errors.New("empty identifier")
type IdentifierConverter interface {
	Convert(identifier []byte) ([]byte, error)
}
type hexIdentifierConverter struct {
	newHash func() hash.Hash
}
func NewDefaultHexIdentifierConverter() (*hexIdentifierConverter, error) {
	return &hexIdentifierConverter{newHash: sha512.New}, nil
}
func (c hexIdentifierConverter) Convert(identifier []byte) ([]byte, error) {
	out := make([]byte, hex.EncodedLen(sha512.Size))
	h := c.newHash()
	if _, err := h.Write(identifier); err != nil {
		return nil, err
	}
	identifier = h.Sum(nil)
	hex.Encode(out, identifier)
	return out, nil
}
type TLSClientIDExtractor interface {
	ExtractClientID(certificate *x509.Certificate) ([]byte, error)
}
type tlsStaticClientIDExtractor struct {
	clientID []byte
}
func NewTLSStaticClientIDExtractor(clientID []byte) (*tlsStaticClientIDExtractor, error) {
	return &tlsStaticClientIDExtractor{clientID: clientID}, nil
}