url_signer

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSignature = errors.New("invalid signature")
	ErrShortToken       = errors.New("token is too small to be valid")
)

Functions

func Epoch

func Epoch(e int64) func(*Protect)

Epoch is a functional option that can be passed to New() to set the Epoch to be used.

func Timestamp

func Timestamp(s *Protect)

Timestamp is a functional option that can be passed to New() to add a timestamp to signatures.

Types

type Protect

type Protect struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Protect is the main struct used to sign and unsigned data

func New

func New(key []byte, options ...func(*Protect)) *Protect

New takes a secret key and returns a new Protect struct. If no Options are provided then minimal defaults will be used. NOTE: The key must be 64 bytes or fewer . If a larger key is provided it will be truncated to 64 bytes.

func (*Protect) Parse

func (s *Protect) Parse(t []byte) Token

func (*Protect) Sign

func (s *Protect) Sign(data []byte) []byte

Sign signs data and returns []byte in the format `data.signature`. Optionally add a timestamp and return to the format `data.timestamp.signature`

func (*Protect) UnSing

func (s *Protect) UnSing(token []byte) ([]byte, error)

UnSing validates a signature and if successful returns the data portion of []byte. If unsuccessful it will return an error and nil for the data.

type Signer

type Signer struct {
	Secret []byte
}

func (*Signer) Expired

func (s *Signer) Expired(token string, minUntilExpire int64) bool

func (*Signer) GenerateToken

func (s *Signer) GenerateToken(data string) string

func (*Signer) VerifyToken

func (s *Signer) VerifyToken(token string) bool

type Token

type Token struct {
	Payload   []byte
	Timestamp time.Time
}

Jump to

Keyboard shortcuts

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