package storage import ( "sync" "github.com/stef/pkiapi/internal/pki" ) // MemoryStore gère le stockage en mémoire des certificats type MemoryStore struct { mu sync.RWMutex certificates map[string]*pki.Certificate } // NewMemoryStore crée une nouvelle instance de MemoryStore func NewMemoryStore() *MemoryStore { return &MemoryStore{ certificates: make(map[string]*pki.Certificate), } } // SaveCertificate sauvegarde un certificat func (s *MemoryStore) SaveCertificate(id string, cert *pki.Certificate) error { s.mu.Lock() defer s.mu.Unlock() s.certificates[id] = cert return nil } // GetCertificate récupère un certificat par ID func (s *MemoryStore) GetCertificate(id string) (*pki.Certificate, error) { s.mu.RLock() defer s.mu.RUnlock() cert, exists := s.certificates[id] if !exists { return nil, ErrNotFound } return cert, nil } // ListCertificates retourne tous les certificats func (s *MemoryStore) ListCertificates() []*pki.Certificate { s.mu.RLock() defer s.mu.RUnlock() certs := make([]*pki.Certificate, 0, len(s.certificates)) for _, cert := range s.certificates { certs = append(certs, cert) } return certs } // Close ferme le store (ne fait rien pour le store mémoire) func (s *MemoryStore) Close() error { return nil } // Deprecated: NewStore utilise maintenant NewMemoryStore // Conservé pour compatibilité func NewStore() CertificateStore { return NewMemoryStore() }