itsrisky

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 14 Imported by: 0

README

itsrisky

a library to generate a data signature use hmac, inspired by itsdangerous

Build Status Coverage Status Go Report Card GoDoc

Install
go get -u github.com/FelixSeptem/itsrisky

Documentation

Overview

Package itsrisky is a library to generate data signature powered by hmac and a hash algorithm(default by SHA1)

itsrisky provide some sign helper method for web application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesString

func BytesString(b []byte) string

convert b to string without copy

func GenerateSecretKey

func GenerateSecretKey(n int) string

if you don't have a long and strong enough secret key,use this method to generate a n length strong secret key quick and safe

func StringBytes

func StringBytes(s string) []byte

return GoString's buffer slice(enable modify string)

Types

type ErrBadData

type ErrBadData struct {
	Data interface{}
	Err  error
}

Err about data format invalid

func (*ErrBadData) Error

func (e *ErrBadData) Error() string

type ErrDataExpired

type ErrDataExpired struct {
	// contains filtered or unexported fields
}

Err about data has been expired

func (*ErrDataExpired) Error

func (e *ErrDataExpired) Error() string

type ErrDataTooShort

type ErrDataTooShort struct {
	DataLength int
}

Err about invalid data length

func (*ErrDataTooShort) Error

func (e *ErrDataTooShort) Error() string

type Serialization

type Serialization struct {
	SecretKey string
	Hash      hash.Hash
	// contains filtered or unexported fields
}

serialization to provide a serializer with web-friendly

func (*Serialization) Dumps

func (s *Serialization) Dumps(in interface{}, expiredTime time.Duration) (string, error)

dump the given data into json and generate a signature with data and deadline information

func (*Serialization) Loads

func (s *Serialization) Loads(data string, receiveData interface{}) (err error)

validate given signed string and check whether the data is expired, return data if string is well signed

func (*Serialization) WithSalt

func (s *Serialization) WithSalt(salt string)

add salt to serialization

type Signer

type Signer struct {
	SecretKey string
	Hash      hash.Hash
}

common signer to provide normal sign method

func (*Signer) Sign

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

to sign the given string with Signer's signature method, separate data between signature with `::`

func (*Signer) Unsign

func (s *Signer) Unsign(value string) (string, error)

validate given signed string, return data if string is well signed

type SignerWithTimeout

type SignerWithTimeout struct {
	SecretKey string
	Hash      hash.Hash
}

signer to provide sign method with timeout

func (*SignerWithTimeout) Sign

func (s *SignerWithTimeout) Sign(value string, expiredTime time.Duration) (string, error)

to sign the given string (include deadline information) with Signer's signature method, separate data between signature with `::`

func (*SignerWithTimeout) Unsign

func (s *SignerWithTimeout) Unsign(value string) (string, error)

validate given signed string and check whether the data is expired, return data if string is well signed

Jump to

Keyboard shortcuts

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