httpsign

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 8 Imported by: 0

README

httpsign

CI Go Reference

httpsign provides utilities for creating, encoding, and verifying signatures within HTTP requests.

Documentation

Overview

Package httpsign provides utilities for signing and verifying HTTP requests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVerification represents a failure to verify a signature.
	ErrVerification = errors.New("signature verification error")
)

Functions

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)

DefaultErrorHandler handles errors as follows:

  • If the error is ErrVerification, it sends a 401 Unauthorized response.
  • For any other errors, it defaults to sending a 500 Internal Server Error response.

Types

type Middleware

type Middleware struct {
	// ErrorHandler is used to handle errors that occur during signature verification.
	// If not provided, DefaultErrorHandler is used.
	ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
	// contains filtered or unexported fields
}

func NewMiddleware

func NewMiddleware(verifier Verifier) *Middleware

NewMiddleware returns a new Middleware given a Verifier.

func (*Middleware) Handler

func (m *Middleware) Handler(h http.Handler) http.Handler

Handler returns a handler that serves requests with signature verification.

type Signer

type Signer interface {
	Sign(message []byte) ([]byte, error)
}

Signer signs messages. It must be safe for concurrent use by multiple goroutines.

type Transport

type Transport struct {
	// Base is the base http.RoundTripper used to make HTTP requests.
	// By default, http.DefaultTransport is used.
	Base http.RoundTripper
	// contains filtered or unexported fields
}

Transport is an HTTP http.RoundTripper which signs outgoing HTTP requests.

func NewTransport

func NewTransport(signer Signer) *Transport

NewTransport returns a new Transport given a Signer.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface, signing the request using provided Signer.

type Verifier

type Verifier interface {
	Verify(message []byte, signature []byte) (bool, error)
}

Verifier verifies message signatures. It must be safe for concurrent use by multiple goroutines.

Directories

Path Synopsis
Package ecdsa provides utilities for signing and verifying messages using ECDSA.
Package ecdsa provides utilities for signing and verifying messages using ECDSA.
Package ed25519 provides utilities for signing and verifying messages using Ed25519.
Package ed25519 provides utilities for signing and verifying messages using Ed25519.
Package hmac provides utilities for signing and verifying messages using HMAC.
Package hmac provides utilities for signing and verifying messages using HMAC.
Package rsa provides utilities for signing and verifying messages using RSA.
Package rsa provides utilities for signing and verifying messages using RSA.

Jump to

Keyboard shortcuts

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