keymanager

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Optional Key Generator
	Generator Generator
}

Config is the configuration for a base KeyManager.

type Disk

type Disk struct {
	// contains filtered or unexported fields
}

Disk extends the base KeyManager to store keys in disk.

func NewDiskKeyManager

func NewDiskKeyManager(generator Generator, keysFilePath string) (*Disk, error)

NewDiskKeyManager creates a new Disk that stores keys in disk.

func (*Disk) GenerateKey

func (d *Disk) GenerateKey(ctx context.Context, keyID string, keyType cryptoutil.KeyType) (Key, error)

GenerateKey generates a new key and stores it in disk.

func (*Disk) GetKey

func (b *Disk) GetKey(ctx context.Context, id string) (Key, error)

func (*Disk) GetKeys

func (b *Disk) GetKeys(ctx context.Context) ([]Key, error)

type Generator

type Generator interface {
	GenerateRSA2048Key() (*rsa.PrivateKey, error)
	GenerateRSA4096Key() (*rsa.PrivateKey, error)
}

Generator is an interface for generating keys.

type Key

type Key interface {
	ID() string
	Signer() crypto.Signer
}

Key is an interface for an opaque key that can be used for signing. It also provides a method for getting the ID of the key.

type KeyEntry

type KeyEntry struct {
	PrivateKey crypto.Signer
	PublicKey  crypto.PublicKey
	// contains filtered or unexported fields
}

KeyEntry is a key entry in the KeyManager. It implements the Key interface.

func (*KeyEntry) ID

func (k *KeyEntry) ID() string

ID returns the ID of the KeyEntry.

func (*KeyEntry) Public

func (k *KeyEntry) Public() crypto.PublicKey

Public returns the public key corresponding to the private key of the KeyEntry.

func (*KeyEntry) Sign

func (k *KeyEntry) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)

Sign signs digest with the private key of the KeyEntry.

func (*KeyEntry) Signer

func (k *KeyEntry) Signer() crypto.Signer

type KeyManager

type KeyManager interface {
	// GenerateKey generates a new key with the given ID and key type.
	// If a key with that ID already exists, it is overwritten.
	GenerateKey(ctx context.Context, id string, keyType cryptoutil.KeyType) (Key, error)

	// GetKey returns the key with the given ID. If the key id does not exist,
	// an error is returned.
	GetKey(ctx context.Context, id string) (Key, error)

	// GetKeys returns all keys managed by the Memory.
	GetKeys(ctx context.Context) ([]Key, error)
}

KeyManager provides a common interface for managing keys.

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory is a key manager that keeps keys in memory.

func NewMemoryKeyManager

func NewMemoryKeyManager(generator Generator) *Memory

func (Memory) GenerateKey

func (b Memory) GenerateKey(ctx context.Context, keyID string, keyType cryptoutil.KeyType) (Key, error)

GenerateKey creates a new key pair and stores it in the KeyManager.

func (Memory) GetKey

func (b Memory) GetKey(ctx context.Context, id string) (Key, error)

func (Memory) GetKeys

func (b Memory) GetKeys(ctx context.Context) ([]Key, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL