httpsignature

package
v0.0.0-...-8eea3e4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

Http Signature

This implements both signing and verification for HTTP signatures in go. It is standalone and can be used as a library.

Documentation

Index

Constants

View Source
const HeaderContentDigest = "content-digest"
View Source
const HeaderSignature = "signature"
View Source
const HeaderSignatureInput = "signature-input"

Variables

View Source
var Now = time.Now

Functions

func Sign

func Sign(req *http.Request, signer signer.SignerI, additionalHeaders ...string) error

Types

type ContentDigest

type ContentDigest struct {
	Algorithm string
	Digest    []byte
}

func NewContentDigest

func NewContentDigest(body []byte) *ContentDigest

func ParseContentDigest

func ParseContentDigest(header string) (*ContentDigest, error)

func (*ContentDigest) Base64

func (c *ContentDigest) Base64() string

func (*ContentDigest) Header

func (c *ContentDigest) Header() []string
type Header interface {
	// returns a tuple (key, value)
	Header() [2]string
}

type SigBase

type SigBase struct {
	*SigParams
	Method        string
	Path          string
	Query         string
	ContentDigest *ContentDigest
	Headers       http.Header
}

func NewSigBase

func NewSigBase(params *SigParams, method string, path string, query string, headers http.Header, body []byte) *SigBase

func SigbaseFrom

func SigbaseFrom(params *SigParams, method string, path string, query string, headers http.Header, digestHeader *ContentDigest) *SigBase

func (*SigBase) Serialize

func (s *SigBase) Serialize() (string, error)

type SigParamKV

type SigParamKV struct {
	Key   string
	Value string
}

type SigParams

type SigParams struct {
	Name string
	// inside the (...)
	Components []string
	// after the (...);
	Attributes []SigParamKV
}

func NewSigParams

func NewSigParams(Created int64, headers ...string) *SigParams

func ParseSigParams

func ParseSigParams(header string) (*SigParams, error)

func Verify

func Verify(req *http.Request, verifier verifier.VerifierI, requiredHeaders ...string) (signatureInput *SigParams, err error)

func VerifyFiber

func VerifyFiber(c *fiber.Ctx, verifier verifier.VerifierI, requiredHeaders ...string) (signatureInput *SigParams, err error)

func VerifyRaw

func VerifyRaw(args VerifyArgs, verifier verifier.VerifierI, requiredHeaders ...string) (signatureInput *SigParams, err error)

func (*SigParams) Header

func (p *SigParams) Header() []string

func (*SigParams) Serialize

func (p *SigParams) Serialize() string

type Signature

type Signature struct {
	Name      string
	Signature []byte
}

func NewSignature

func NewSignature(signature []byte) *Signature

func ParseSignature

func ParseSignature(header string) (*Signature, error)

func (*Signature) Base64

func (sig *Signature) Base64() string

func (*Signature) Header

func (sig *Signature) Header() []string

type VerifyArgs

type VerifyArgs struct {
	Body           []byte
	Method         string
	Path           string
	Query          string
	Signature      string
	SignatureInput string
	ContentDigest  string
	Headers        http.Header
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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