Documentation
¶
Overview ¶
Package cookie provides functions for securely setting and retrieving HTTP cookies using the SecureCookie library.
See the SecureCookie README for more information on how this library works.
This package provides the following functions and types: - Set: Set a cookie value using base64 encoding and append the HMAC signature. - Get: Retrieve a cookie value and verify its HMAC signature. - SetSigned: Set a cookie value using base64 encoding and append the HMAC signature, then sign the entire value with the secret key. - GetSigned: Retrieve a cookie value and verify its HMAC signature, then decode the value using the secret key.
Index ¶
- Variables
- func Delete(ctx *xun.Context, v http.Cookie)
- func Get(ctx *xun.Context, name string) (string, error)
- func GetSigned(ctx *xun.Context, name string, secretKey []byte) (string, *time.Time, error)
- func Set(ctx *xun.Context, v http.Cookie) error
- func SetSigned(ctx *xun.Context, v http.Cookie, secretKey []byte) (time.Time, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrValueTooLong = errors.New("cookie value too long") ErrInvalidValue = errors.New("invalid cookie value") )
Functions ¶
func Delete ¶
Delete deletes a cookie by setting the MaxAge to -1 and setting the value to an empty string.
func Get ¶
Get retrieves a cookie value using base64 decoding
If the length of the resulting cookie is longer than 4096 bytes, an ErrValueTooLong error is returned.
func GetSigned ¶
GetSigned retrieves a cookie value using HMAC-SHA256 verification
This function takes a secret key as an argument and uses it to calculate a HMAC signature of the cookie name and value. This signature is compared to the signature stored in the cookie. If the two signatures match, the original cookie value is returned. Otherwise, an ErrInvalidValue error is returned.
If the length of the resulting cookie value is longer than 4096 bytes, an ErrValueTooLong error is returned.
func Set ¶
Set sets a cookie value using base64 encoding
If the length of the resulting cookie is longer than 4096 bytes, an ErrValueTooLong error is returned.
func SetSigned ¶
SetSigned sets a cookie value using HMAC-SHA256 and appends the signature to the value.
This function takes a secret key as an argument and uses it to calculate a HMAC signature of the cookie name and value. This signature is prepended to the value before setting the cookie.
If the length of the resulting cookie value is longer than 4096 bytes, an ErrValueTooLong error is returned.
Types ¶
This section is empty.