hmacsha

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package hmacsha provides a simple token implementation using the hmac-sha256 algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Key       []byte
	Signature []byte
}

Token implements a simple abstraction around generating tokens using the hmac-sha256 algorithm.

func FromKey

func FromKey(secret []byte, key []byte) *Token

FromKey will return a new token that is constructed using the specified secret and key.

Note: The secret and the token key should both at least have a length of 16 characters to be considered unguessable.

func Generate

func Generate(secret []byte, length int) (*Token, error)

Generate will return a new token that is constructed using the specified secret and random key of the specified length.

Note: The secret and the to be generated token key should both at least have a length of 16 characters to be considered unguessable.

func MustGenerate

func MustGenerate(secret []byte, length int) *Token

MustGenerate will generate a token using Generate and panic instead of returning an error.

Note: The cryptographically secure pseudo-random number generator provided by the operating system may fail. However, such a fail would mean that something seriously must be wrong with the machine running this code.

func Parse

func Parse(secret []byte, str string) (*Token, error)

Parse will parse a token that is in its string representation.

func (*Token) Equal

func (t *Token) Equal(signature []byte) bool

Equal returns true then the specified signature is the same as the tokens signature.

Note: This method should be used over just comparing the byte slices as it computed in constant time and limits certain attacks.

func (*Token) KeyString

func (t *Token) KeyString() string

KeyString returns a string (base64) representation of the key.

func (*Token) SignatureString

func (t *Token) SignatureString() string

SignatureString returns a string (base64) representation of the signature.

func (*Token) String

func (t *Token) String() string

String returns a string representation of the whole token.

func (*Token) Valid

func (t *Token) Valid(secret []byte) bool

Valid returns true when the tokens key matches its signature.

Jump to

Keyboard shortcuts

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