keyring

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAuth = errors.New("invalid keyring auth")

ErrInvalidAuth if auth is invalid.

View Source
var ErrLocked = errors.New("keyring is locked")

ErrLocked if no keyring key is set.

View Source
var ErrNotAnItem = errors.New("not an encoded keyring item")

ErrNotAnItem if value in keyring is not an encoded keyring item. TODO: Add test.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets package log

Types

type Auth

type Auth interface {
	Key() SecretKey
}

Auth ...

func NewKeyAuth

func NewKeyAuth(key SecretKey) Auth

NewKeyAuth returns auth with a key.

func NewPasswordAuth

func NewPasswordAuth(password string, salt []byte) (Auth, error)

NewPasswordAuth generates key from password, salt and secret key.

type Item

type Item struct {
	ID   string
	Type string
	// contains filtered or unexported fields
}

Item is a keyring entry.

func DecodeItem

func DecodeItem(b []byte, secretKey SecretKey) (*Item, error)

DecodeItem returns Item from bytes. If encrypted and secret key is specified, it will have the decrypted data and will return (*Item, true, nil).

func NewItem

func NewItem(id string, secret Secret, typ string) *Item

NewItem creates an Item with a secret.

func (*Item) Marshal

func (i *Item) Marshal(secretKey SecretKey) ([]byte, error)

Marshal to bytes. If secretKey is specified we store the data encrypted.

func (*Item) Secret

func (i *Item) Secret() *Secret

Secret ...

func (*Item) SecretData

func (i *Item) SecretData() []byte

SecretData ...

func (*Item) SecretDataFor

func (i *Item) SecretDataFor(name string) []byte

SecretDataFor ...

func (*Item) SecretFor

func (i *Item) SecretFor(name string) *Secret

SecretFor returns a named secret.

func (*Item) SetSecret

func (i *Item) SetSecret(val Secret)

SetSecret sets the secret.

func (*Item) SetSecretFor

func (i *Item) SetSecretFor(name string, val Secret)

SetSecretFor sets a named secret.

type Keyring

type Keyring interface {
	// Get item.
	// Requires Unlock().
	Get(id string) (*Item, error)

	// Set item.
	// Requires Unlock().
	Set(i *Item) error

	// Delete item.
	// Doesn't require Unlock().
	Delete(id string) (bool, error)

	// List items.
	// Requires Unlock().
	// Items with ids that start with "." are not returned by List.
	List(opts *ListOpts) ([]*Item, error)

	// IDs.
	// Doesn't require Unlock().
	// Items with ids that start with "." are not returned by IDs.
	IDs(prefix string) ([]string, error)

	// Exists returns true it has the id.
	// Doesn't require Unlock().
	Exists(id string) (bool, error)

	// Unlock with auth.
	Unlock(auth Auth) error

	// Lock.
	Lock() error

	// Salt is default salt value, generated on first access and persisted
	// until ResetAuth() or Reset().
	// This salt value is not encrypted in the keyring.
	// Doesn't require Unlock().
	Salt() ([]byte, error)

	// Authed returns true if Keyring has ever been unlocked.
	// Doesn't require Unlock().
	Authed() (bool, error)

	// Reset keyring.
	// Doesn't require Unlock().
	Reset() error
}

Keyring defines an interface for accessing keyring items.

func NewFS added in v0.4.5

func NewFS(dir string) (Keyring, error)

NewFS creates a Keyring using the local filesystem. This is an alternate Keyring implementation that is platform agnostic.

func NewKeyring

func NewKeyring(service string) (Keyring, error)

NewKeyring ...

func NewMem added in v0.4.5

func NewMem() Keyring

NewMem returns an in memory Keyring useful for testing or ephemeral keys. The Keyring is unlocked (setup with a random key).

type ListOpts

type ListOpts struct {
	Type string
}

ListOpts ...

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger interface used in this package

type Secret

type Secret struct {
	Data []byte `json:"data"`
}

Secret for item.

func NewSecret

func NewSecret(b []byte) Secret

NewSecret returns a new secret with data.

func NewStringSecret

func NewStringSecret(s string) Secret

NewStringSecret returns a new secret for a string.

func (*Secret) String added in v0.4.10

func (s *Secret) String() string

String returns secret data as a string.

type SecretKey

type SecretKey *[32]byte

SecretKey for encrypting items.

Jump to

Keyboard shortcuts

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