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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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