mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-24 15:09:39 -05:00
0036b24266
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
45 lines
998 B
Go
45 lines
998 B
Go
/*
|
|
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.
|
|
func (s *Storage) Get(_ context.Context, keyID string) ([]byte, error) {
|
|
encDEK, ok := s.dekPool[keyID]
|
|
if ok {
|
|
return encDEK, nil
|
|
}
|
|
return nil, storage.ErrDEKUnset
|
|
}
|
|
|
|
// Put saves a DEK to Storage by key ID.
|
|
func (s *Storage) Put(_ context.Context, keyID string, encDEK []byte) error {
|
|
s.dekPool[keyID] = encDEK
|
|
return nil
|
|
}
|