smokering

package module
v0.0.0-...-ec88b49 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

README

Smoke Ring

GoDoc Build Status


A minimal in-memory encrypted keyring using only standard libs.

Smoke Ring is encryption agnostic, it is designed to be used as a package by another application where the application provides the block cipher for encrypting the keys. This means the application only has to keep track of the master key for this cipher while all their keys are safely stored in Smoke Ring.

Documentation

Index

Constants

View Source
const (
	// StatusUnknown should only ever be set on an improperly intialized key.
	StatusUnknown uint = iota
	// StatusNew is for a new key that has never been decrypted or used.
	StatusNew
	// StatusUsed is set on a key that's been decryted at least once.
	StatusUsed
	// StatusDisabled is set on a key that's been disabled.
	StatusDisabled
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Key represents an encryption key.

func (*Key) AsJSON

func (k *Key) AsJSON() ([]byte, error)

AsJSON returns the key data serialized as JSON to allow saving a Key.

func (*Key) Decrypt

func (k *Key) Decrypt(block cipher.Block, blocksize int) ([]byte, error)

Decrypt and decode the key so that it may be used. block is the block cipher generated from the smokering master key.

func (*Key) Disable

func (k *Key) Disable()

Disable sets the status on a key to disabled, the keyring will not return it again after this.

func (*Key) FromJSON

func (k *Key) FromJSON(byt []byte) error

FromJSON sets the key data from JSON to allow restoring a key state.

func (*Key) GetNote

func (k *Key) GetNote() string

GetNote gets the note from the key.

func (*Key) GetStatus

func (k *Key) GetStatus() uint

GetStatus gets the current key status.

func (*Key) GobDecode

func (k *Key) GobDecode(byt []byte) error

GobDecode implements the GobDecoder interface to allow restoring a key state.

func (*Key) GobEncode

func (k *Key) GobEncode() ([]byte, error)

GobEncode implements the GobEncoder interface to allow saving a Key.

func (*Key) ID

func (k *Key) ID() string

ID returns the key ID.

func (*Key) SetNote

func (k *Key) SetNote(note string)

SetNote sets the note on the key.

type Smokering

type Smokering struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Smokering stores encryption keys protected by a master key.

func New

func New() *Smokering

New returns a new Smokering encrypted with master key.

func NewFromGob

func NewFromGob(byt []byte) (*Smokering, error)

NewFromGob restores a Smokering from a Gob []byte.

func NewFromJSON

func NewFromJSON(byt []byte) (*Smokering, error)

NewFromJSON restores a Smokering from a JSON []byte.

func (*Smokering) AsJSON

func (sr *Smokering) AsJSON() ([]byte, error)

AsJSON returns a Smokering's data serialized as JSON to allow saving a Smokering.

func (*Smokering) GetKey

func (sr *Smokering) GetKey(id string) *Key

GetKey gets a key from the keyring using it's ID.

func (*Smokering) GobEncode

func (sr *Smokering) GobEncode() ([]byte, error)

GobEncode implements the GobEncoder interface to allow saving a Smokering.

func (*Smokering) Key

func (sr *Smokering) Key(id, note string, block cipher.Block, blocksize int, f func() ([]byte, error)) (*Key, error)

Key adds a new key to the Smokering and returns it. block is the block cipher used to encrypt the keys (generally an AES cipher encrypted with a master key). blocksize is the size of the block used to encrypt the keys (e.g. aes.BlockSize) f is provided to generate the key.

func (*Smokering) KeyFromGob

func (sr *Smokering) KeyFromGob(byt []byte) (*Key, error)

KeyFromGob adds a key to the Smokering from Gob encoded key data, returning the key.

func (*Smokering) KeyFromJSON

func (sr *Smokering) KeyFromJSON(byt []byte) (*Key, error)

KeyFromJSON adds a key to the Smokering from JSON encoded key data, returning the key.

Jump to

Keyboard shortcuts

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