cookie

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2018 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

Functions

func NewWithOptions

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.

Types

type Manager

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

Manager struct used to manage and process secure cookie.

func NewManager

func NewManager(opts *Options, signKey, encKey string) (*Manager, error)

NewManager method returns the new cookie manager.

func (*Manager) Decode

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

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

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

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

func (*Manager) Write

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

Write method writes the given cookie value into response.

type Options

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

Options to hold session cookie options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL