forked from quic-go/quic-go
create interface for crypto.CertManager
This commit is contained in:
@@ -7,14 +7,26 @@ import (
|
||||
)
|
||||
|
||||
// CertManager manages the certificates sent by the server
|
||||
type CertManager struct {
|
||||
type CertManager interface {
|
||||
SetData([]byte) error
|
||||
GetLeafCert() []byte
|
||||
}
|
||||
|
||||
type certManager struct {
|
||||
chain [][]byte
|
||||
}
|
||||
|
||||
var _ CertManager = &certManager{}
|
||||
|
||||
var errNoCertificateChain = errors.New("No certicifate chain loaded")
|
||||
|
||||
// NewCertManager creates a new CertManager
|
||||
func NewCertManager() CertManager {
|
||||
return &certManager{}
|
||||
}
|
||||
|
||||
// SetData takes the byte-slice sent in the SHLO and decompresses it into the certificate chain
|
||||
func (c *CertManager) SetData(data []byte) error {
|
||||
func (c *certManager) SetData(data []byte) error {
|
||||
chain, err := decompressChain(data)
|
||||
if err != nil {
|
||||
return qerr.ProofInvalid
|
||||
@@ -26,7 +38,7 @@ func (c *CertManager) SetData(data []byte) error {
|
||||
|
||||
// GetLeafCert returns the leaf certificate of the certificate chain
|
||||
// it errors if the certificate chain has not yet been set
|
||||
func (c *CertManager) GetLeafCert() []byte {
|
||||
func (c *certManager) GetLeafCert() []byte {
|
||||
if len(c.chain) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Cert Manager", func() {
|
||||
var cm *CertManager
|
||||
var cm *certManager
|
||||
|
||||
BeforeEach(func() {
|
||||
cm = &CertManager{}
|
||||
cm = NewCertManager().(*certManager)
|
||||
})
|
||||
|
||||
It("errors when given invalid data", func() {
|
||||
|
||||
Reference in New Issue
Block a user