signature

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SignAppID         string = "app"
	SignKeySign       string = "sign"
	SignKeyTimestamp  string = "ts"
	SignKeyNoise      string = "noise"
	SignBody          string = "bs_body"
	SignToken         string = "access_token"
	SignAuthorization string = "Authorization"
)

Variables

This section is empty.

Functions

func Abs

func Abs(v int64) int64

func DefaultNoiseRand

func DefaultNoiseRand() string

func HashMac added in v1.2.0

func HashMac(f func() hash.Hash, secret string, rawArr ...string) string

HashMac

func HashMacMD5 added in v1.2.0

func HashMacMD5(secret string, rawArr ...string) string

HashMacMD5 hmac md5

func HashMacSha1

func HashMacSha1(secret string, rawArr ...string) string

HashMacSha1 hmac sha1

func NewOption

func NewOption() *option

func NewSignInHeadRequest added in v1.2.0

func NewSignInHeadRequest(s Signature, rawQuery url.Values) func(context.Context, string, string, io.Reader) (*http.Request, error)

func NewSignInURLRequest added in v1.2.0

func NewSignInURLRequest(s Signature, rawQuery url.Values) func(context.Context, string, string, io.Reader) (*http.Request, error)

func NewUnSignRequest added in v1.2.0

func NewUnSignRequest(_ Signature, rawQuery url.Values) func(context.Context, string, string, io.Reader) (*http.Request, error)

func RandString

func RandString(n int, allowedChars ...[]rune) string

func VerifySign

func VerifySign(req *http.Request, opts ...OptionFunc) error

Types

type DefaultSignature

type DefaultSignature struct {
	AppID     string
	Sign      string
	Timestamp int64
	Noise     string
}

func (*DefaultSignature) GetAppID added in v1.1.2

func (s *DefaultSignature) GetAppID() string

func (*DefaultSignature) GetNoise

func (s *DefaultSignature) GetNoise() string

func (*DefaultSignature) GetSign

func (s *DefaultSignature) GetSign() string

func (*DefaultSignature) GetTimestamp

func (s *DefaultSignature) GetTimestamp() int64

func (*DefaultSignature) ToMap added in v1.2.0

func (s *DefaultSignature) ToMap() url.Values

type GenerateFunc

type GenerateFunc func(GenerateParam, ...OptionFunc) (Signature, error)

type GenerateParam added in v1.2.0

type GenerateParam struct {
	Method      string           // http method
	ContentType core.ContentType // content type
	Host        string           // host
	Action      string           // action
	UrlQuery    url.Values       // url query params
	BsBody      []byte           // body, if method is not GET
	AccessToken string           // access_token
}

type OptionFunc

type OptionFunc func(*option)

func WithAppID added in v1.2.0

func WithAppID(v string) OptionFunc

WithAppID set app_id, when generate

func WithExpire

func WithExpire(v time.Duration) OptionFunc

WithExpire set timestamp expire, when verify

func WithHmacFunc

func WithHmacFunc(f func(secret string, rawArr ...string) string) OptionFunc

WithHmacFunc set hmac func, when generate & verify. default is hmac sha1

func WithNoiseFunc

func WithNoiseFunc(f func() string) OptionFunc

WithNoiseFunc set noise generate func, when generate

func WithSecret

func WithSecret(v string) OptionFunc

WithSecret set secret, when generate or verify

func WithToken added in v1.3.0

func WithToken(iswith bool) OptionFunc

WithToken sign hmac with token

func WithUnSignedKey added in v1.1.1

func WithUnSignedKey(v ...string) OptionFunc

WithUnSignedKey set unsigned field, when generate & verify

type RequestWithContext added in v1.2.0

type RequestWithContext func(context.Context, string, string, io.Reader) (*http.Request, error)

type SignSetMode added in v1.2.0

type SignSetMode uint8
const (
	SignSetNil SignSetMode = iota
	SignSetInHead
	SignSetlInURL
)

func (SignSetMode) RequestWithContextFunc added in v1.2.0

func (s SignSetMode) RequestWithContextFunc(sign Signature, rawQuery url.Values) func(context.Context, string, string, io.Reader) (*http.Request, error)

type Signature

type Signature interface {
	GetSign() string
	GetTimestamp() int64
	GetNoise() string
	GetAppID() string
	ToMap() url.Values
}

func Generate

func Generate(p GenerateParam, opts ...OptionFunc) (Signature, error)

func NewSignatureFrmRequest

func NewSignatureFrmRequest(req *http.Request) (Signature, url.Values)

Jump to

Keyboard shortcuts

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