signedvalue

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 8 Imported by: 1

README

signedvalue

signedvalue is an implementation of signed and timestamped strings compatible with Tornado's create_signed_value, decode_signed_value, and therefore set_secure_cookie and get_secure_cookie.

Install

go get github.com/sashka/signedvalue

Usage

import "github.com/sashka/signedvalue"

// Sign your "Hello, world".
signed := signedvalue.Create("secret", "name", "Hello, world")

// Decode a signed string.
// Treat signed string as invalid if it's more than 1 minute old.
decoded, err := signedvalue.Decode("secret", "name", signed, 60)
if err != nil {
    // Signed string is no longer valid.
}

Contributing

Pull requests are kindly welcome.

Documentation

Overview

Package signedvalue provides signed and timestamped strings compatible with Tornado's create_signed_value and decode_signed_value.

Only v2 format is supported.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("invalid secret key")

ErrInvalidKey means that a key with requested version had not been found.

View Source
var ErrInvalidName = errors.New("invalid name")

ErrInvalidName means that the name inside the signed value didn't match with a name passed to the decode function.

View Source
var ErrInvalidSignature = errors.New("invalid signature")

ErrInvalidSignature means that the signature could not be verified.

View Source
var ErrMalformedField = errors.New("malformed field")

ErrMalformedField means that a field is broken and cannot be decoded properly.

View Source
var ErrSignatureExpired = errors.New("signature expired")

ErrSignatureExpired means that the signature expired, thus the signed value should not be trusted any more.

View Source
var ErrSignatureInFuture = errors.New("signature in future")

ErrSignatureInFuture means that the timestamp is in future and cannot be checked properly, thus should not be trusted.

View Source
var ErrValueDecodeFailed = errors.New("value decode failed")

ErrValueDecodeFailed literally means that value could not be decoded.

Functions

func Create

func Create(key string, name string, value string) string

Create creates signed and timestamped string so the string cannot be forged. This method doesn't support secret key versioning.

func CreateWithKeyVersioning

func CreateWithKeyVersioning(keys map[int]string, keyVersion int, name string, value string) (string, error)

CreateWithKeyVersioning creates signed and timestamped string using the given secret key version.

func Decode

func Decode(key string, name string, signed string, ttl int) (string, error)

Decode decodes and returns the value if it validates. This method doesn't support secret key versioning.

func DecodeWithKeyVersioning

func DecodeWithKeyVersioning(keys map[int]string, name string, signed string, ttl int) (decoded string, error error)

DecodeWithKeyVersioning decodes and retures the value if it validates.

Types

This section is empty.

Jump to

Keyboard shortcuts

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