internal

package
v0.0.0-...-b0a73f8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(one, two []string) bool

Equal compares two HMACs. Equal means that the data is signed by at least one of the secrets of both HMACs.

func MergeHashes

func MergeHashes(hashes ...map[Algorithm][]hash.Hash) map[Algorithm][]hash.Hash

func NewSHA256

func NewSHA256(secret ...string) map[Algorithm][]hash.Hash

func NewSHA512

func NewSHA512(secret ...string) map[Algorithm][]hash.Hash

Types

type Algorithm

type Algorithm string

Algorithm is the type for HMAC algorithms.

const (
	SHA256      Algorithm = "sha256"
	SHA256Short Algorithm = "256"
	SHA512      Algorithm = "sha512"
	SHA512Short Algorithm = "512"
)

type HMAC

type HMAC struct {
	// Hashes is a map of algorithms to a slice of hash.Hash. The slice is used to support multiple secrets.
	Hashes map[Algorithm][]hash.Hash
	// NoPrefix doesn't prefix the algorithm to the signature. The default is for the prefix to be added. Example: sha256=abc123
	NoPrefix bool
}

HMAC is the HMAC configuration for signing data.

func NewHMAC

func NewHMAC() HMAC

func (HMAC) Sign

func (h HMAC) Sign(data []byte) (map[Algorithm][]string, error)

type Signature

type Signature struct {
	// BaseHeader is the header name that should contain the signature(s). Example: X-Rufio-Signature
	BaseHeader string
	// DisableAlgoHeader decides whether to append the algorithm to the signature header or not. Default is to append.
	// Example: X-Rufio-Signature becomes X-Rufio-Signature-256
	// When set to false, a header will be added for each algorithm. Example: X-Rufio-Signature-256 and X-Rufio-Signature-512
	DisableAlgoHeader bool
	// PayloadHeaders are headers whose values will be included in the signature payload. Example: X-Rufio-Timestamp
	PayloadHeaders []string
	// HMAC is the HMAC to use for signing
	HMAC HMAC
}

Signature contains the configuration for signing HTTP requests.

func (Signature) AddSignature

func (s Signature) AddSignature(req *http.Request) error

Jump to

Keyboard shortcuts

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