hmac

package
v0.0.0-...-0f445ee Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DomainName = "hmac"
)

Variables

View Source
var (
	ErrTokenSignatureMismatch = errors.New("token signature mismatch")
	ErrInvalidTokenFormat     = errors.New("invalid token")
)

Functions

func HashByteSecret

func HashByteSecret(secret []byte) []byte

HashByteSecret hashes the secret for consumption by the AEAD encryption algorithm which expects exactly 32 bytes.

The system secret is being hashed to always match exactly the 32 bytes required by AEAD, even if the secret is long or shorter.

func HashStringSecret

func HashStringSecret(secret string) []byte

HashStringSecret hashes the secret for consumption by the AEAD encryption algorithm which expects exactly 32 bytes.

The system secret is being hashed to always match exactly the 32 bytes required by AEAD, even if the secret is long or shorter.

func RandomBytes

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

RandomBytes returns n random bytes by reading from crypto/rand.Reader

func Registrate

func Registrate(ctx context.Context, cfg *Config) (context.Context, error)

Types

type Config

type Config struct {
	TokenEntropy int           `envconfig:"default=100"`
	SystemSecret string        `envconfig:"default=you_Really_Need_To_ChangeThis!!!"`
	TTL          time.Duration `envconfig:"default=24h"`
}

type HMACToken

type HMACToken struct {
	GlobalSecret []byte
	sync.Mutex
	// contains filtered or unexported fields
}

func Get

func Get(ctx context.Context) (*HMACToken, error)

func (*HMACToken) Generate

func (c *HMACToken) Generate() (string, string, error)

Generate generates a token and a matching signature or returns an error. This method implements rfc6819 Section 5.1.4.2.2: Use High Entropy for Secrets.

func (*HMACToken) Signature

func (c *HMACToken) Signature(token string) string

func (*HMACToken) Validate

func (c *HMACToken) Validate(token string) (err error)

Validate validates a token and returns its signature or an error if the token is not valid.

Jump to

Keyboard shortcuts

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