Documentation
¶
Overview ¶
Package sookie provides a simple way to set and get cookies with encryption and compression. It uses the XChaCha20-Poly1305 AEAD algorithm for encryption and Zstandard for compression. The cookie value is base64 encoded and can be safely sent over HTTP headers.
Index ¶
- Variables
- func Del(w http.ResponseWriter, r *http.Request, cookie http.Cookie)
- func Get[V any](secret []byte, r *http.Request, name string) (V, error)
- func Open[V any](secret []byte, raw string) (V, error)
- func Seal[V any](secret []byte, expires time.Time, value V) (string, error)
- func Set[V any](secret []byte, w http.ResponseWriter, value V, cookie http.Cookie) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrExpired is returned when the cookie has expired. ErrExpired = errors.New("sookie: cookie expired") )
Functions ¶
func Del ¶ added in v0.2.0
Del deletes a cookie with the given name from the response, if it was present in the request.
func Get ¶
Get retrieves a cookie with the given name from the request. The cookie value is decrypted and decompressed using the XChaCha20-Poly1305 AEAD algorithm. The cookie value is unmarshaled into the given type V. If the cookie is not found, the http.ErrNoCookie error is returned. If the cookie is expired, the ErrExpired error is returned.
func Open ¶ added in v0.4.0
Open retrieves a value from the raw encrypted string. The raw value is decrypted and decompressed using the XChaCha20-Poly1305 AEAD algorithm. The raw value is unmarshaled into the given type V. If the raw value is expired, the ErrExpired error is returned.
func Seal ¶ added in v0.4.0
Seal encodes a Value. The value is encrypted and compressed using the XChaCha20-Poly1305 AEAD algorithm and Zstandard compression. The expiry time, if non-zero will be used when Opening the value to ensure it has not expired.
func Set ¶
Set sets a cookie with the given value. The value is encrypted and compressed using the XChaCha20-Poly1305 AEAD algorithm and Zstandard compression. The cookie is set with the given name and options. MaxAge or Expires may optionally be set to control the expiration of the cookie. MaxAge takes precedence over Expires. The http.Cookie `Value` field must be empty and the passed in value will me marshaled and used instead. The cookie will be deleted if MaxAge is less than 0 (and an empty value will be sent).
Types ¶
This section is empty.