func NewKeyRepository(config KeyRepositoryConfig) (storage.KeyRepository, error) {
	err := config.defaults()
	if err != nil {
		return nil, fmt.Errorf("invalid configuration: %w", err)
	}
	return &keyRepository{
		publicKeysPath:  config.PublicKeysPath,
		privateKeysPath: config.PrivateKeysPath,
		keyFactory:      config.KeyFactory,
		fileManager:     config.FileManager,
		logger:          config.Logger,
	}, nil
}
NewKeyRepository returns a new file system based key repository that knows
how to load keys based on files.
Public keys will be loaded in a discovery mode.
package fs
import (
	"bufio"
	"bytes"
	"context"
	"fmt"
	"io/fs"
	"os"
	"path/filepath"
	"github.com/slok/agebox/internal/key"
	"github.com/slok/agebox/internal/log"
	"github.com/slok/agebox/internal/model"
	"github.com/slok/agebox/internal/storage"
)
type keyRepository struct {
	publicKeysPath  string
	privateKeysPath string
	keyFactory      key.Factory
	fileManager     FileManager
	logger          log.Logger
}
type KeyRepositoryConfig struct {
	PublicKeysPath  string
	PrivateKeysPath string
	KeyFactory      key.Factory
	FileManager     FileManager
	Logger          log.Logger
}
func (c *KeyRepositoryConfig) defaults() error {
	if c.KeyFactory == nil {
		return fmt.Errorf("key factory is required")
	}
	c.PublicKeysPath = filepath.Clean(c.PublicKeysPath)
	c.PrivateKeysPath = filepath.Clean(c.PrivateKeysPath)
	if c.FileManager == nil {
		c.FileManager = defaultFileManager
	}
	if c.Logger == nil {
		c.Logger = log.Noop
	}
	c.Logger = c.Logger.WithValues(log.Kv{"svc": "storage.fs.KeyRepository"})
	return nil
}