contentdigest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SHA256 = Digester{
	Key:      "sha-256",
	HashFunc: sha256.New,
	MaxBytes: 10485760,
}

SHA256 is a digester which uses the SHA256 hashing algorithm and key, with MaxBytes set to 10MB.

View Source
var SHA384 = Digester{
	Key:      "sha-384",
	HashFunc: sha512.New384,
	MaxBytes: 10485760,
}

SHA384 is a digester which uses the SHA384 hashing algorithm and key, with MaxBytes set to 10MB.

View Source
var SHA512 = Digester{
	Key:      "sha-512",
	HashFunc: sha512.New,
	MaxBytes: 10485760,
}

SHA512 is a digester which uses the SHA512 hashing algorithm and key, with MaxBytes set to 10MB.

Functions

This section is empty.

Types

type Digester

type Digester struct {
	// Key to give the digest.
	Key string
	// HashFunc is a function which returns the hashing algorithm to use.
	HashFunc func() hash.Hash

	// MaxBytes is the limit of bytes to read to prevent DOS attacks.
	MaxBytes int64
}

Digester creates a HTTP request digest in the format specified by https://www.rfc-editor.org/rfc/rfc9530.html#content-digest.

func (Digester) HashRequest

func (d Digester) HashRequest(w http.ResponseWriter, r *http.Request) (string, error)

HashRequest hashes a HTTP request and returns a string following the specification in https://www.rfc-editor.org/rfc/rfc9530.html#content-digest

Hashing is performed by reading the HTTP request into memory. To prevent DOS, a http.MaxBytesReader is used to limit the body size that can be read.

'w' is used to signal to the Go HTTP library that a connection should be closed if the client is exceeding the maximum bytes. When using this client-side, 'w' may be set to nil.

Jump to

Keyboard shortcuts

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