diff --git a/certdb.go b/certdb.go index 26b2a36..fc39bc2 100644 --- a/certdb.go +++ b/certdb.go @@ -34,6 +34,34 @@ type CertificateRecord struct { RevokeReason int `json:"revokeReason,omitempty"` } +// Look for a certifcate by its name +func (c *CAState) FindByName(name string, all bool) *CertificateRecord { + for _, cert := range c.Certificates { + if cert.RevokedAt != "" && !all { + continue + } + if cert.Name == name { + return &cert + } + } + + return nil +} + +// Look for a certificate by its serial +func (c *CAState) FindBySerial(serial string, all bool) *CertificateRecord { + for _, cert := range c.Certificates { + if cert.RevokedAt != "" && !all { + continue + } + if cert.Serial == serial { + return &cert + } + } + + return nil +} + // func caStatePath() string { // return filepath.Join(filepath.Dir(caConfigPath), caConfig.GetStateFileName()) // }