keystore

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyPassphrase   = errors.New("passphrase is empty")
	ErrVersionMismatch   = errors.New("version mismatch")
	ErrCipherMismatch    = errors.New("cipher mismatch")
	ErrMACMismatch       = errors.New("mac mismatch")
	ErrEmptyKeysDir      = errors.New("keysDir is empty")
	ErrEmptyNodeIdentity = errors.New("nodeIdentityData is empty")
	ErrKeyNotFound       = errors.New("key not found on this node")
	ErrTokenInvalid      = errors.New("token is invalid")
	ErrNotUnlockedKey    = errors.New("key is not unlocked")
)

Functions

This section is empty.

Types

type BasicKeyStore

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

BasicKeyStore handles keypair storage. TODO: add cache?

func New

func New(fs afero.Fs, keysDir string) (*BasicKeyStore, error)

New creates a new BasicKeyStore.

func (*BasicKeyStore) Delete

func (ks *BasicKeyStore) Delete(keyID string, passphrase string) error

Delete removes the file referencing the given key.

func (*BasicKeyStore) Exists

func (ks *BasicKeyStore) Exists(key string) bool

Exists returns whether a key is stored

func (*BasicKeyStore) Get

func (ks *BasicKeyStore) Get(keyID string, passphrase string) (*Key, error)

Get unlocks a key by keyID.

func (*BasicKeyStore) ListKeys

func (ks *BasicKeyStore) ListKeys() ([]string, error)

ListKeys lists the keys in the keysDir.

func (*BasicKeyStore) Save

func (ks *BasicKeyStore) Save(id string, data []byte, passphrase string) (string, error)

Save encrypts a key and writes it to a file.

type Key

type Key struct {
	ID   string
	Data []byte
}

Key represents a keypair to be stored in a keystore

func NewKey

func NewKey(id string, data []byte) (*Key, error)

NewKey creates new Key

func UnmarshalKey

func UnmarshalKey(data []byte, passphrase string) (*Key, error)

UnmarshalKey decrypts and unmarhals the private key

func (*Key) MarshalToJSON

func (key *Key) MarshalToJSON(passphrase string) ([]byte, error)

MarshalToJSON encrypts and marshals a key to json byte array.

func (*Key) PrivKey

func (key *Key) PrivKey() (crypto.PrivKey, error)

PrivKey acts upon a Key which its `Data` is a private key. The method unmarshals the raw pvkey bytes.

type KeyStore

type KeyStore interface {
	Save(id string, data []byte, passphrase string) (string, error)
	Get(keyID string, passphrase string) (*Key, error)
	Delete(keyID string, passphrase string) error
	ListKeys() ([]string, error)
}

KeyStore manages a local keystore with lock and unlock functionalities.

type ScryptParams

type ScryptParams struct {
	N          int    `json:"n"`
	R          int    `json:"r"`
	P          int    `json:"p"`
	DKeyLength int    `json:"dklen"`
	Salt       string `json:"salt"`
}

ScryptParams

Jump to

Keyboard shortcuts

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