create interface for crypto.CertManager

This commit is contained in:
Marten Seemann
2016-11-11 19:49:04 +07:00
parent 992678b9d7
commit f6cef67c3d
4 changed files with 39 additions and 9 deletions

View File

@@ -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
}

View File

@@ -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() {