itsdangerous

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 11 Imported by: 0

README

license Codeship Status

go-itsdangerous

Like itsdangerous but for Go.

Documentation

Overview

Package itsdangerous implements various functions to deal with untrusted sources. Mainly useful for web applications.

This package exists purely as a port of https://github.com/mitsuhiko/itsdangerous, where the original version is written in Python.

Index

Constants

View Source
const EPOCH = 1293840000

2011/01/01 in UTC

Variables

This section is empty.

Functions

This section is empty.

Types

type HMACAlgorithm

type HMACAlgorithm struct {
	DigestMethod func() hash.Hash
}

HMACAlgorithm provides signature generation using HMACs.

func (*HMACAlgorithm) GetSignature

func (a *HMACAlgorithm) GetSignature(key, value string) []byte

GetSignature returns the signature for the given key and value.

func (*HMACAlgorithm) VerifySignature

func (a *HMACAlgorithm) VerifySignature(key, value string, sig []byte) bool

VerifySignature verifies the given signature matches the expected signature.

type Signature

type Signature struct {
	SecretKey     string
	Sep           string
	Salt          string
	KeyDerivation string
	DigestMethod  func() hash.Hash
	Algorithm     SigningAlgorithm
}

Signature can sign bytes and unsign it and validate the signature provided.

Salt can be used to namespace the hash, so that a signed string is only valid for a given namespace. Leaving this at the default value or re-using a salt value across different parts of your application where the same signed value in one part can mean something different in another part is a security risk.

func NewSignature

func NewSignature(secret, salt, sep, derivation string, digest func() hash.Hash, algo SigningAlgorithm) *Signature

NewSignature creates a new Signature

func (*Signature) DeriveKey

func (s *Signature) DeriveKey() (string, error)

DeriveKey generates a key derivation. Keep in mind that the key derivation in itsdangerous is not intended to be used as a security method to make a complex key out of a short password. Instead you should use large random secret keys.

func (*Signature) Get

func (s *Signature) Get(value string) (string, error)

Get returns the signature for the given value.

func (*Signature) Sign

func (s *Signature) Sign(value string) (string, error)

Sign the given string.

func (*Signature) Unsign

func (s *Signature) Unsign(signed string) (string, error)

Unsign the given string.

func (*Signature) Verify

func (s *Signature) Verify(value, sig string) (bool, error)

Verify verifies the signature for the given value.

type SigningAlgorithm

type SigningAlgorithm interface {
	GetSignature(key, value string) []byte
	VerifySignature(key, value string, sig []byte) bool
}

SigningAlgorithm provides interfaces to generate and verify signature

type TimestampSignature

type TimestampSignature struct {
	Signature
}

TimestampSignature works like the regular Signature but also records the time of the signing and can be used to expire signatures.

func NewTimestampSignature

func NewTimestampSignature(secret, salt, sep, derivation string, digest func() hash.Hash, algo SigningAlgorithm) *TimestampSignature

NewTimestampSignature creates a new TimestampSignature

func (*TimestampSignature) Sign

func (s *TimestampSignature) Sign(value string) (string, error)

Sign the given string.

func (*TimestampSignature) Unsign

func (s *TimestampSignature) Unsign(value string, maxAge uint32) (string, error)

Unsign the given string.

Jump to

Keyboard shortcuts

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