heat

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExpiredToken = xo.BF("expired token")

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

View Source
var ErrInvalidToken = xo.BF("invalid token")

ErrInvalidToken is returned if a token is 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.

func UnsafeFastHash added in v0.32.0

func UnsafeFastHash()

UnsafeFastHash can be called to set the minimum allowed hash cost. This should only be used for speeding up automated tests.

Types

type Base

type Base struct {
	// The key id.
	ID coal.ID

	// The key expiry.
	Expiry time.Time
}

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

func (*Base) GetAccessor added in v0.28.0

func (b *Base) GetAccessor(v interface{}) *stick.Accessor

GetAccessor implements the Key interface.

func (*Base) GetBase added in v0.27.0

func (b *Base) GetBase() *Base

GetBase implements the Key interface.

type Key

type Key interface {
	Validate() error
	GetBase() *Base
	GetAccessor(interface{}) *stick.Accessor
}

Key is a structure used to encode a key.

type Meta

type Meta struct {
	// The key name.
	Name string

	// The key expiry.
	Expiry time.Duration

	// The accessor.
	Accessor *stick.Accessor
}

Meta contains meta information about a key.

func GetMeta added in v0.28.0

func GetMeta(key Key) *Meta

GetMeta 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 than 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   stick.Map
}

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