From 9b7b995e9775ef460c10a0fa89f479011c7ca858 Mon Sep 17 00:00:00 2001 From: Slawek Koszewski Date: Mon, 28 Jul 2025 18:57:57 +0200 Subject: [PATCH] Added function that can look for a certificate in the database. --- certdb.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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()) // }