heat

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2020 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExpiredToken = errors.New("expired token")

ErrExpiredToken is returned if a token is expired but otherwise valid.

View Source
var ErrInvalidToken = errors.New("invalid token")

ErrInvalidToken is returned if a token is in some way invalid.

Functions

func Compare

func Compare(hash []byte, str string) error

Compare will safely compare the specified hash to its unhashed version and return nil if they match.

func CompareBytes

func CompareBytes(hash, bytes []byte) error

CompareBytes will safely compare the specified hash to its unhashed version and return nil if they match.

func Hash

func Hash(str string) ([]byte, error)

Hash uses bcrypt to safely compute a hash. The returned hash can be converted to readable string.

func HashBytes

func HashBytes(bytes []byte) ([]byte, error)

HashBytes uses bcrypt to safely compute a hash. The returned hash can be converted to readable string.

func Issue

func Issue(secret []byte, issuer, name string, key RawKey) (string, error)

Issue will sign a token from the specified raw key.

func MustHash

func MustHash(str string) []byte

MustHash will call Hash and panic on errors.

func MustHashBytes

func MustHashBytes(bytes []byte) []byte

MustHashBytes will call HashBytes and panic on errors.

func MustRand

func MustRand(n int) []byte

MustRand will call Rand and panic on errors.

func Rand

func Rand(n int) ([]byte, error)

Rand will return n secure random bytes.

Types

type Base

type Base struct {
	ID     coal.ID
	Expiry time.Time
}

Base can be embedded in a struct to turn it into a key.

type Data

type Data map[string]interface{}

Data is generic JSON object.

type Key

type Key interface {
	// Validate should validate the token.
	Validate() error
	// contains filtered or unexported methods
}

Key is a structure used to encode a key.

type KeyMeta

type KeyMeta struct {
	Name   string
	Expiry time.Duration
}

KeyMeta contains meta information about a key.

func Meta

func Meta(key Key) KeyMeta

Meta will parse the keys "heat" tag on the embedded heat.Base struct and return the encoded name and default expiry.

type Notary

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

Notary is used to issue and verify tokens from keys.

func NewNotary

func NewNotary(name string, secret []byte) *Notary

NewNotary creates a new notary with the specified name and secret. It will panic if the name is missing or the specified secret is less that 16 bytes.

func (*Notary) Issue

func (n *Notary) Issue(key Key) (string, error)

Issue will generate a token from the specified key.

func (*Notary) Verify

func (n *Notary) Verify(key Key, token string) error

Verify will verify the specified token and fill the specified key.

type RawKey

type RawKey struct {
	ID     string
	Expiry time.Time
	Data   Data
}

RawKey represents a raw key.

func Verify

func Verify(secret []byte, issuer, name, token string) (*RawKey, error)

Verify will verify the specified token and return the decoded raw key.

type Secret

type Secret []byte

Secret wraps a bytes secret to allow key derivation.

func (Secret) Derive

func (s Secret) Derive(str string) Secret

Derive will derive a key using the provided string.

func (Secret) DeriveBytes

func (s Secret) DeriveBytes(bytes []byte) Secret

DeriveBytes will derive a key using the provided bytes.

Jump to

Keyboard shortcuts

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