diff --git a/notifier/keystore.go b/notifier/keystore.go deleted file mode 100644 index 8a7420a538..0000000000 --- a/notifier/keystore.go +++ /dev/null @@ -1,44 +0,0 @@ -package notifier - -import ( - "context" - "crypto/rsa" - "time" - - "github.com/google/uuid" -) - -type Key struct { - ID uuid.UUID - Expiration time.Time - Public *rsa.PublicKey -} - -// KeyStore stores and retrieves RSA public keys in -// PKIX, ASN.1 DER form -// -// internally x509.ParsePKIXPublicKey is used to parse and return a *rsa.PublicKey to the caller. -type KeyStore interface { - // Keys returns all stored public keys. - Keys(ctx context.Context) ([]Key, error) - // KeyByID returns a public key if exists. - // Returns clairerror.ErrKeyNotFound if key does not exist. - KeyByID(ctx context.Context, ID uuid.UUID) (Key, error) - // PutKey persists a public key with an initial expiration of n + current time. - // - // BumpExpiration is expected to be called periodically to keep the public key alive. - PutKey(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error - // DeleteKey removes a public key from the keystore. - // - // Returns clairerror.ErrKeyNotFound if key does not exist. - DeleteKey(ctx context.Context, ID uuid.UUID) error - // BumpExpiration sets the public key's expiration to n + - // current time. - BumpExpiration(ctx context.Context, ID uuid.UUID, n time.Duration) error - // GC performs garbage collection o f expired public certificates. - // N is the number of records deleted. - // - // Implementations are free to define efficient GC procedures. - // Callers of this method may repeat GC until 0 is returned. - GC(ctx context.Context) (n int64, err error) -} diff --git a/notifier/mockkeystore.go b/notifier/mockkeystore.go deleted file mode 100644 index efead9fe04..0000000000 --- a/notifier/mockkeystore.go +++ /dev/null @@ -1,62 +0,0 @@ -package notifier - -import ( - "context" - "crypto/rsa" - "time" - - "github.com/google/uuid" -) - -var _ KeyStore = (*MockKeyStore)(nil) - -// MockKeyStore implements a mock KeyStore. -type MockKeyStore struct { - Keys_ func(ctx context.Context) ([]Key, error) - KeyByID_ func(ctx context.Context, ID uuid.UUID) (Key, error) - PutKey_ func(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error - DeleteKey_ func(ctx context.Context, ID uuid.UUID) error - BumpExpiration_ func(ctx context.Context, ID uuid.UUID, n time.Duration) error - GC_ func(ctx context.Context) (n int64, err error) -} - -// Keys returns all stored public keys. -func (m *MockKeyStore) Keys(ctx context.Context) ([]Key, error) { - return m.Keys_(ctx) -} - -// KeyByID returns a public key if exists. -// Returns clairerror.ErrKeyNotFound if key does not exist. -func (m *MockKeyStore) KeyByID(ctx context.Context, ID uuid.UUID) (Key, error) { - return m.KeyByID_(ctx, ID) -} - -// PutKey persists a public key with a default expiration of 5 minutes. -// -// A BumpExpiration call is expected to occur sometime before this default -// expiration. -func (m *MockKeyStore) PutKey(ctx context.Context, ID uuid.UUID, key *rsa.PublicKey, n time.Duration) error { - return m.PutKey_(ctx, ID, key, n) -} - -// DeleteKey removes a public key from the keystore. -// -// Returns clairerror.ErrKeyNotFound if key does not exist. -func (m *MockKeyStore) DeleteKey(ctx context.Context, ID uuid.UUID) error { - return m.DeleteKey(ctx, ID) -} - -// BumpExpiration sets the public key's expiration to (n minutes) + -// (time of call). -func (m *MockKeyStore) BumpExpiration(ctx context.Context, ID uuid.UUID, n time.Duration) error { - return m.BumpExpiration_(ctx, ID, n) -} - -// GC performs garbage collection of expired public certificates. -// N is the number of records deleted. -// -// Implementations are free to define efficient GC procedures. -// Callers of this method may repeat GC until 0 is returned. -func (m *MockKeyStore) GC(ctx context.Context) (n int64, err error) { - return m.GC_(ctx) -}