signature

package
v0.0.0-...-a7b5525 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsDuration

func AbsDuration(d time.Duration) time.Duration

AbsDuration returns the absolute value of the supplied duration.

func BuildSigningPayload

func BuildSigningPayload(ts time.Time, canonicalBody []byte) []byte

BuildSigningPayload constructs the canonical string that is HMAC-signed.

func CanonicalizeJSONBody

func CanonicalizeJSONBody(raw []byte) ([]byte, error)

CanonicalizeJSONBody normalizes arbitrary JSON into canonical form for signing.

func ParseTimestamp

func ParseTimestamp(value string) (time.Time, error)

ParseTimestamp accepts Timestamp header values in RFC3339 or RFC3339Nano format.

func ReadAndBufferBody

func ReadAndBufferBody(r *http.Request) ([]byte, error)

ReadAndBufferBody reads the request body while keeping it accessible for later handlers.

Types

type HMACVerifier

type HMACVerifier struct {
	Key []byte
}

HMACVerifier validates signatures that were produced by taking the base64url-encoded HMAC-SHA256 of `RFC3339(timestamp) + "." + canonicalJSON`.

func (HMACVerifier) Verify

func (v HMACVerifier) Verify(_ context.Context, material Material) error

Verify implements Verifier by recomputing the expected HMAC signature.

type Material

type Material struct {
	Signature     string
	Timestamp     time.Time
	CanonicalBody []byte
	Method        string
	Path          string
	RawQuery      string
	Headers       http.Header
}

Material captures the inputs needed to validate a signed request.

type Verifier

type Verifier interface {
	Verify(ctx context.Context, material Material) error
}

Verifier validates the authenticity of incoming requests.

type VerifierFunc

type VerifierFunc func(ctx context.Context, material Material) error

VerifierFunc lifts bare functions into Verifier.

func (VerifierFunc) Verify

func (f VerifierFunc) Verify(ctx context.Context, material Material) error

Verify delegates to the wrapped function.

Jump to

Keyboard shortcuts

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