Added error type to X509FileStore

Signed-off-by: Diogo Monica <diogo@docker.com>
This commit is contained in:
Diogo Monica 2015-07-16 23:52:45 -07:00
parent 17c9fcd911
commit 945691912a
4 changed files with 20 additions and 4 deletions

View File

@ -214,7 +214,7 @@ func (s *X509FileStore) getCertificateByCertID(certID CertID) (*x509.Certificate
return cert, nil return cert, nil
} }
return nil, errors.New("certificate not found in Key Store") return nil, &ErrNoCertificatesFound{query: string(certID)}
} }
// GetCertificatesByCN returns all the certificates that match a specific // GetCertificatesByCN returns all the certificates that match a specific
@ -233,7 +233,7 @@ func (s *X509FileStore) GetCertificatesByCN(cn string) ([]*x509.Certificate, err
} }
} }
if len(certs) == 0 { if len(certs) == 0 {
return nil, errors.New("common name not found in Key Store") return nil, &ErrNoCertificatesFound{query: cn}
} }
return certs, nil return certs, nil

View File

@ -157,7 +157,7 @@ func (s *X509MemStore) getCertificateByCertID(certID CertID) (*x509.Certificate,
return cert, nil return cert, nil
} }
return nil, errors.New("certificate not found in Key Store") return nil, &ErrNoCertificatesFound{query: string(certID)}
} }
// GetCertificatesByCN returns all the certificates that match a specific // GetCertificatesByCN returns all the certificates that match a specific
@ -176,7 +176,7 @@ func (s *X509MemStore) GetCertificatesByCN(cn string) ([]*x509.Certificate, erro
} }
} }
if len(certs) == 0 { if len(certs) == 0 {
return nil, errors.New("common name not found in Key Store") return nil, &ErrNoCertificatesFound{query: cn}
} }
return certs, nil return certs, nil

View File

@ -8,6 +8,18 @@ import (
const certExtension string = "crt" const certExtension string = "crt"
// ErrNoCertificatesFound is returned when no certificates are found for a
// GetCertificatesBy*
type ErrNoCertificatesFound struct {
query string
}
// ErrNoCertificatesFound is returned when no certificates are found for a
// GetCertificatesBy*
func (err ErrNoCertificatesFound) Error() string {
return fmt.Sprintf("error, no certificates found in the keystore match: %s", err.query)
}
// X509Store is the interface for all X509Stores // X509Store is the interface for all X509Stores
type X509Store interface { type X509Store interface {
AddCert(cert *x509.Certificate) error AddCert(cert *x509.Certificate) error

View File

@ -169,6 +169,10 @@ func LoadCertBundleFromPEM(pemBytes []byte) ([]*x509.Certificate, error) {
} }
} }
if len(certificates) == 0 {
return nil, fmt.Errorf("no valid certificates found")
}
return certificates, nil return certificates, nil
} }