security

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidContentType is an error that indicates invalid content type.
	ErrInvalidContentType = errors.New("invalid content type")
	// ErrInvalidHeader is an error that indicates invalid X-Content-Security header.
	ErrInvalidHeader = errors.New("invalid X-Content-Security header")
	// ErrInvalidKey is an error that indicates invalid key.
	ErrInvalidKey = errors.New("invalid key")
	// ErrInvalidPublicKey is an error that indicates invalid public key.
	ErrInvalidPublicKey = errors.New("invalid public key")
	// ErrInvalidSecret is an error that indicates invalid secret.
	ErrInvalidSecret = errors.New("invalid secret")
)

Functions

func VerifySignature

func VerifySignature(r *http.Request, securityHeader *ContentSecurityHeader, tolerance time.Duration) int

VerifySignature verifies the signature in given r.

Types

type ContentSecurityHeader

type ContentSecurityHeader struct {
	Key         []byte
	Timestamp   string
	ContentType int
	Signature   string
}

A ContentSecurityHeader is a content security header.

func ParseContentSecurity

func ParseContentSecurity(decrypters map[string]codec.RsaDecrypter, r *http.Request) (
	*ContentSecurityHeader, error)

ParseContentSecurity parses content security settings in give r.

func (*ContentSecurityHeader) Encrypted

func (h *ContentSecurityHeader) Encrypted() bool

Encrypted checks if it's a crypted request.

type WithCodeResponseWriter

type WithCodeResponseWriter struct {
	Writer http.ResponseWriter
	Code   int
}

A WithCodeResponseWriter is a helper to delay sealing a http.ResponseWriter on writing code.

func (*WithCodeResponseWriter) Flush

func (w *WithCodeResponseWriter) Flush()

Flush flushes the response writer.

func (*WithCodeResponseWriter) Header

func (w *WithCodeResponseWriter) Header() http.Header

Header returns the http header.

func (*WithCodeResponseWriter) Hijack

Hijack implements the http.Hijacker interface. This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.

func (*WithCodeResponseWriter) Write

func (w *WithCodeResponseWriter) Write(bytes []byte) (int, error)

Write writes bytes into w.

func (*WithCodeResponseWriter) WriteHeader

func (w *WithCodeResponseWriter) WriteHeader(code int)

WriteHeader writes code into w, and not sealing the writer.

Jump to

Keyboard shortcuts

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