Documentation ¶
Overview ¶
Package signedcookie provides a secure cookie manager for Go web applications.
Index ¶
Constants ¶
const SecretSize = 32 // SecretSize is the size, in bytes, of a cookie secret.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCookie ¶ added in v0.0.45
BaseCookie is a type alias for http.Cookie. It is used for providing and overriding default cookie settings. Note that the Name, HttpOnly, and Secure fields are ignored. The expires field is not ignored, but it will be overridden by an explicitly set TTL.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the creation, signing, and verification of secure cookies.
func NewManager ¶
NewManager creates a new Manager instance with the provided secrets. It returns an error if no secrets are provided or if any secret is invalid.
func (Manager) NewDeletionCookie ¶ added in v0.0.45
NewDeletionCookie creates a new cookie that will delete the specified cookie when sent to the client.
func (Manager) NewSignedCookie ¶ added in v0.0.45
NewSignedCookie creates a new cookie with a signed value based on the provided unsigned cookie.
type Secrets ¶ added in v0.0.2
type Secrets []string
Secrets is a latest-first list of 32-byte, base64-encoded secrets.
type SignedCookie ¶ added in v0.0.20
type SignedCookie[T any] struct { Manager *Manager TTL time.Duration BaseCookie BaseCookie }
SignedCookie provides methods for working with signed cookies of a specific type T.
func (*SignedCookie[T]) NewDeletionCookie ¶ added in v0.0.45
func (sc *SignedCookie[T]) NewDeletionCookie() *http.Cookie
NewDeletionCookie creates a new cookie that will delete the current cookie when sent to the client.
func (*SignedCookie[T]) NewSignedCookie ¶ added in v0.0.45
func (sc *SignedCookie[T]) NewSignedCookie(unsignedValue *T, overrideBaseCookie BaseCookie) (*http.Cookie, error)
NewSignedCookie creates a new signed cookie with the provided value and optional override settings.
func (*SignedCookie[T]) VerifyAndReadCookieValue ¶ added in v0.0.45
func (sc *SignedCookie[T]) VerifyAndReadCookieValue(r *http.Request) (*T, error)
VerifyAndReadCookieValue retrieves and verifies the value of the signed cookie from the request. It returns the decoded value of type T or an error if retrieval or verification fails.