Documentation
¶
Index ¶
- Variables
- func NewCookie(name, value string, policy CookiePolicy) *fiber.Cookie
- func Read(c fiber.Ctx, name string) (string, error)
- func ReadEncrypted(c fiber.Ctx, name string, cfg EncryptedConfig, deps CryptoDeps) (string, error)
- func ReadSigned(c fiber.Ctx, name string, cfg SignedConfig) (string, error)
- func Write(c fiber.Ctx, cookie *fiber.Cookie, cfg WriteConfig) error
- func WriteEncrypted(c fiber.Ctx, cookie *fiber.Cookie, cfg EncryptedConfig, deps CryptoDeps) error
- func WriteSigned(c fiber.Ctx, cookie *fiber.Cookie, cfg SignedConfig) error
- type CookiePolicy
- type CryptoDeps
- type EncryptedConfig
- type SignedConfig
- type WriteConfig
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewCookie ¶
func NewCookie(name, value string, policy CookiePolicy) *fiber.Cookie
NewCookie builds a Fiber cookie using a shared policy.
func ReadEncrypted ¶
func ReadEncrypted(c fiber.Ctx, name string, cfg EncryptedConfig, deps CryptoDeps) (string, error)
ReadEncrypted reads an encrypted cookie value from the request and decrypts it using the secret key from config. The cookie name is authenticated in the encrypted payload so values cannot be replayed across different cookie names. If decryption fails or the authenticated name does not match, it returns ErrInvalidValue.
func ReadSigned ¶
ReadSigned reads a signed cookie value and validates its HMAC signature.
func WriteEncrypted ¶
func WriteEncrypted(c fiber.Ctx, cookie *fiber.Cookie, cfg EncryptedConfig, deps CryptoDeps) error
WriteEncrypted encrypts the cookie value using the secret key from config and writes it to the response. The cookie name is included in the encrypted payload so the value cannot be replayed for other cookie names.
func WriteSigned ¶
WriteSigned encodes the cookie value using base64, signs it with a HMAC.
Types ¶
type CookiePolicy ¶
type CookiePolicy struct {
Path string
Domain string
Expires time.Time
MaxAge int
Secure bool
HTTPOnly bool
SameSite string
SessionOnly bool
Partitioned bool
}
CookiePolicy defines reusable cookie attributes for API-wide defaults.
func DefaultCookiePolicy ¶
func DefaultCookiePolicy() CookiePolicy
DefaultCookiePolicy returns a secure default cookie policy.
type CryptoDeps ¶
type CryptoDeps struct {
Encrypt func(secretKey, plaintext string) (string, error)
Decrypt func(secretKey, ciphertext string) (string, error)
}
CryptoDeps defines encryption/decryption dependencies for cookie helpers.
func DefaultCryptoDeps ¶
func DefaultCryptoDeps() CryptoDeps
DefaultCryptoDeps returns production crypto implementations.
type EncryptedConfig ¶
type EncryptedConfig struct {
SecretKey string
Write WriteConfig
}
EncryptedConfig defines encryption configuration for encrypted cookies.
type SignedConfig ¶
type SignedConfig struct {
SecretKey []byte
Write WriteConfig
}
SignedConfig defines HMAC configuration for signed cookies.
type WriteConfig ¶
type WriteConfig struct {
MaxSerializedSize int
}
WriteConfig defines behavior for serialized cookie size enforcement.
func DefaultWriteConfig ¶
func DefaultWriteConfig() WriteConfig
DefaultWriteConfig returns default write constraints.