hmacauth

package
v0.0.0-...-bca7abf Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SigSeparator is the separator character in the signature that separates the algorithm from the signature.
	SigSeparator = "="
)

Variables

This section is empty.

Functions

func CryptoHashToDigestName

func CryptoHashToDigestName(id crypto.Hash) (result string, err error)

CryptoHashToDigestName returns the algorithm name corresponding to the crypto.Hash ID, or an error if the algorithm is not supported.

func DigestNameToCryptoHash

func DigestNameToCryptoHash(name string) (result crypto.Hash, err error)

DigestNameToCryptoHash returns the crypto.Hash value corresponding to the algorithm name, or an error if the algorithm is not supported.

Types

type AuthenticationResult

type AuthenticationResult int

AuthenticationResult is a code used to identify the outcome of HmacAuth.AuthenticateRequest().

const (
	// ResultNoSignature - the incoming result did not have a signature
	// header.
	ResultNoSignature AuthenticationResult = iota

	// ResultInvalidFormat - the signature header was not parseable.
	ResultInvalidFormat

	// ResultUnsupportedAlgorithm - the signature header specified an
	// unsupported algorithm.
	ResultUnsupportedAlgorithm

	// ResultMatch - the signature from the request header matched the
	// locally-computed signature.
	ResultMatch

	// ResultMismatch - the signature from the request header did not match
	// the locally-computed signature.
	ResultMismatch
)

func (AuthenticationResult) String

func (result AuthenticationResult) String() string

type HmacAuth

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

HmacAuth signs outbound requests and authenticates inbound requests.

func NewHmacAuth

func NewHmacAuth(hash crypto.Hash, key []byte, header string, headers []string, bodyOnly bool) *HmacAuth

NewHmacAuth returns an HmacAuth object that can be used to sign or authenticate HTTP requests based on the supplied parameters.

func (*HmacAuth) AuthenticateRequest

func (auth *HmacAuth) AuthenticateRequest(request *http.Request) (
	result AuthenticationResult, headerSignature,
	computedSignature string)

AuthenticateRequest authenticates the request, returning the result code, the signature from the header, and the locally-computed signature.

func (*HmacAuth) RequestSignature

func (auth *HmacAuth) RequestSignature(req *http.Request) string

RequestSignature Generates a signature for the request.

func (*HmacAuth) SignRequest

func (auth *HmacAuth) SignRequest(req *http.Request)

func (*HmacAuth) SignatureFromHeader

func (auth *HmacAuth) SignatureFromHeader(req *http.Request) string

SignatureFromHeader retrieves the signature included in the request header.

func (*HmacAuth) StringToSign

func (auth *HmacAuth) StringToSign(req *http.Request) string

StringToSign Produces the string that will be prefixed to the request body and used to generate the signature.

Jump to

Keyboard shortcuts

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