2023-03-02 09:08:31 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Package memfs implements a storage backend for the KMS that stores keys in memory only.
|
|
|
|
// This package should be used for testing only.
|
|
|
|
package memfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Storage is the standard implementation of the Storage interface, storing keys in memory only.
|
|
|
|
type Storage struct {
|
|
|
|
dekPool map[string][]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates and initializes a new Storage object.
|
|
|
|
func New() *Storage {
|
|
|
|
s := &Storage{
|
|
|
|
dekPool: make(map[string][]byte),
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns a DEK from Storage by key ID.
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *Storage) Get(_ context.Context, keyID string) ([]byte, error) {
|
2023-03-02 09:08:31 -05:00
|
|
|
encDEK, ok := s.dekPool[keyID]
|
|
|
|
if ok {
|
|
|
|
return encDEK, nil
|
|
|
|
}
|
|
|
|
return nil, storage.ErrDEKUnset
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put saves a DEK to Storage by key ID.
|
2023-03-20 06:03:36 -04:00
|
|
|
func (s *Storage) Put(_ context.Context, keyID string, encDEK []byte) error {
|
2023-03-02 09:08:31 -05:00
|
|
|
s.dekPool[keyID] = encDEK
|
|
|
|
return nil
|
|
|
|
}
|