hmac

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderSignature is the header containing the HMAC signature
	HeaderSignature = "X-Signature"
	// HeaderTimestamp is the header containing the request timestamp
	HeaderTimestamp = "X-Timestamp"
)

Variables

This section is empty.

Functions

func ComputeSignature

func ComputeSignature(method, path, query, timestamp string, body []byte, secret string) string

ComputeSignature computes the HMAC-SHA256 signature for an HTTP request The signature is computed as: HMAC-SHA256(method + path + query + timestamp + body, secret)

func ParseJSONResponse

func ParseJSONResponse(resp *http.Response, target interface{}) error

ParseJSONResponse parses a JSON response from an HTTP response

func ValidateSignature

func ValidateSignature(method, path, query, timestamp string, body []byte, signature, secret string) bool

ValidateSignature validates an HMAC signature

Types

type Client

type Client struct {
	BaseURL    string
	HMACSecret string
	HTTPClient *http.Client
}

Client handles HMAC-authenticated HTTP requests

func NewClient

func NewClient(config Config) *Client

NewClient creates a new HMAC HTTP client

func (*Client) DoRequest

func (c *Client) DoRequest(method, path string, body interface{}) (*http.Response, error)

DoRequest makes an HMAC-authenticated HTTP request

func (*Client) DoRequestWithBody

func (c *Client) DoRequestWithBody(method, path string, bodyBytes []byte) (*http.Response, error)

DoRequestWithBody makes an HMAC-authenticated HTTP request with raw body bytes

type Config

type Config struct {
	BaseURL    string
	HMACSecret string
	Timeout    time.Duration
}

Config holds configuration for HMAC client

Jump to

Keyboard shortcuts

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