aahframe.work: aahframe.work/security/cookie Index | Files

package cookie

import "aahframe.work/security/cookie"

Index

Package Files

cookie.go

Variables

var (
    ErrCookieValueIsTooLarge    = errors.New("security/cookie: value is greater than 4096")
    ErrCookieValueIsInvalid     = errors.New("security/cookie: value is not valid")
    ErrCookieInvaildTimestamp   = errors.New("security/cookie: timestamp is invalid")
    ErrCookieTimestampIsTooNew  = errors.New("security/cookie: timestamp is too new")
    ErrCookieTimestampIsExpired = errors.New("security/cookie: timestamp expried")
    ErrSignVerificationIsFailed = errors.New("security/cookie: sign verification is failed")
)

Cookie errors

func NewWithOptions Uses

func NewWithOptions(value string, opts *Options) *http.Cookie

NewWithOptions method returns http.Cookie with the options set from `session {...}`. It also sets the `Expires` field calculated based on the MaxAge value.

type Manager Uses

type Manager struct {
    Options *Options
    // contains filtered or unexported fields
}

Manager struct used to manage and process secure cookie.

func NewManager Uses

func NewManager(opts *Options, keys ...string) (*Manager, error)

NewManager method returns the new cookie manager.

Example:

cookieMgr := cookie.NewManager(options)
cookieMgr := cookie.NewManager(options, signKey, encKey)
cookieMgr := cookie.NewManager(options, signKey, encKey, oldSignKey, oldEncKey)

func (*Manager) Decode Uses

func (m *Manager) Decode(value string) ([]byte, error)

Decode method decodes the secure cookie value.

It performs:

1) Checks max cookie size i.e 4Kb
2) Decodes the value using Base64
3) Validates the signed data
4) Validates timestamp
5) Decodes the value using Base64
6) Decrypts the value

func (*Manager) Encode Uses

func (m *Manager) Encode(b []byte) (string, error)

Encode method encodes given value.

It performs:

1) Encrypts it if encryption key configured
2) Signs the value if sign key configured
3) Encodes value into Base64 string
4) Checks max cookie size i.e 4Kb

func (*Manager) New Uses

func (m *Manager) New(value string) *http.Cookie

New method creates new cookie instance for given value with cookie manager options.

func (*Manager) Write Uses

func (m *Manager) Write(w http.ResponseWriter, value string)

Write method writes the given cookie value into response.

type Options Uses

type Options struct {
    Name     string
    Domain   string
    Path     string
    MaxAge   int64
    HTTPOnly bool
    Secure   bool
    SameSite string
}

Options to hold session cookie options.

Package cookie imports 11 packages (graph) and is imported by 6 packages. Updated 2019-03-26. Refresh now. Tools for package owners.