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 ¶
This section is empty.
Variables ¶
var NowFunc = time.Now
Function used to obtain the current time. Defaults to time.Now, but can be overridden eg for unit tests to simulate a different current time.
Functions ¶
This section is empty.
Types ¶
type HMACAlgorithm ¶
HMACAlgorithm provides signature generation using HMACs.
func (*HMACAlgorithm) GetSignature ¶
func (a *HMACAlgorithm) GetSignature(key []byte, value string) []byte
GetSignature returns the signature for the given key and value.
func (*HMACAlgorithm) VerifySignature ¶
func (a *HMACAlgorithm) VerifySignature(key []byte, value string, signature []byte) bool
VerifySignature verifies the given signature matches the expected signature.
type InvalidSignatureError ¶
type InvalidSignatureError struct {
// contains filtered or unexported fields
}
func (InvalidSignatureError) Error ¶
func (e InvalidSignatureError) Error() string
func (InvalidSignatureError) Unwrap ¶
func (e InvalidSignatureError) Unwrap() error
type SignatureExpiredError ¶
type SignatureExpiredError struct {
// contains filtered or unexported fields
}
func (SignatureExpiredError) Error ¶
func (e SignatureExpiredError) Error() string
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer 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 NewSigner ¶
NewSigner creates a new Signer with the given secret and salt. All other properties will be set to match the Python itsdangerous defaults.
func NewSignerWithOptions ¶
func NewSignerWithOptions(secret, salt, sep, derivation string, digest func() hash.Hash, algo SigningAlgorithm) (*Signer, error)
NewSignerWithOptions creates a new Signer allowing overiding the default properties.
type SigningAlgorithm ¶
type SigningAlgorithm interface { GetSignature(key []byte, value string) []byte VerifySignature(key []byte, value string, signature []byte) bool }
SigningAlgorithm provides interfaces to generate and verify signature
type TimestampSigner ¶
type TimestampSigner struct {
Signer
}
TimestampSigner works like the regular Signer but also records the time of the signing and can be used to expire signatures.
func NewTimestampSigner ¶
func NewTimestampSigner(secret, salt string) *TimestampSigner
NewTimestampSigner creates a new TimestampSigner with the given secret and salt. All other properties will be set to match the Python itsdangerous defaults.
func NewTimestampSignerWithOptions ¶
func NewTimestampSignerWithOptions(secret, salt, sep, derivation string, digest func() hash.Hash, algo SigningAlgorithm) (*TimestampSigner, error)
NewTimestampSignerWithOptions creates a new TimestampSigner allowing overiding the default properties.
func (*TimestampSigner) Sign ¶
func (s *TimestampSigner) Sign(value string) string
Sign the given string.
type URLSafeSerializer ¶
type URLSafeSerializer struct {
Signer
}
func NewURLSafeSerializer ¶
func NewURLSafeSerializer(secret, salt string) *URLSafeSerializer
func (*URLSafeSerializer) Marshal ¶
func (s *URLSafeSerializer) Marshal(value interface{}) (string, error)
func (*URLSafeSerializer) Unmarshal ¶
func (s *URLSafeSerializer) Unmarshal(signed string, value interface{}) error
type URLSafeTimedSerializer ¶
type URLSafeTimedSerializer struct {
TimestampSigner
}
func NewURLSafeTimedSerializer ¶
func NewURLSafeTimedSerializer(secret, salt string) *URLSafeTimedSerializer
func (*URLSafeTimedSerializer) Marshal ¶
func (s *URLSafeTimedSerializer) Marshal(value interface{}) (string, error)