session

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MIT Imports: 7 Imported by: 116

Documentation

Overview

Package session implements session storage.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocalStorageIsNotAvailable = xerrors.New("localStorage is not available")

ErrLocalStorageIsNotAvailable is returned if localStorage is not available and Storage can't use it.

View Source
var ErrNotFound = errors.New("session storage: not found")

ErrNotFound means that session is not found in storage.

Functions

This section is empty.

Types

type Data

type Data struct {
	Config    tg.Config
	DC        int
	Addr      string
	AuthKey   []byte
	AuthKeyID []byte
	Salt      int64
}

Data of session.

type FileStorage

type FileStorage struct {
	Path string
	// contains filtered or unexported fields
}

FileStorage implements SessionStorage for file system as file stored in Path.

func (*FileStorage) LoadSession

func (f *FileStorage) LoadSession(_ context.Context) ([]byte, error)

LoadSession loads session from file.

func (*FileStorage) StoreSession

func (f *FileStorage) StoreSession(_ context.Context, data []byte) error

StoreSession stores session to file.

type Loader

type Loader struct {
	Storage Storage
}

Loader wraps Storage implementing Data (un-)marshaling.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) (*Data, error)

Load loads Data from Storage.

func (*Loader) Save

func (l *Loader) Save(ctx context.Context, data *Data) error

Save saves Data to Storage.

type Storage

type Storage interface {
	LoadSession(ctx context.Context) ([]byte, error)
	StoreSession(ctx context.Context, data []byte) error
}

Storage is secure persistent storage for client session.

NB: Implementation security is important, attacker can abuse it not only for connecting as authenticated user or bot, but even decrypting previous messages in some situations.

type StorageMemory

type StorageMemory struct {
	// contains filtered or unexported fields
}

StorageMemory implements in-memory session storage. Goroutine-safe.

func (*StorageMemory) LoadSession

func (s *StorageMemory) LoadSession(ctx context.Context) ([]byte, error)

LoadSession loads session from memory.

func (*StorageMemory) StoreSession

func (s *StorageMemory) StoreSession(ctx context.Context, data []byte) error

StoreSession stores session to memory.

type WebLocalStorage added in v0.40.0

type WebLocalStorage struct {
	Key string
}

WebLocalStorage is a Web Storage API based session storage.

func (WebLocalStorage) LoadSession added in v0.40.0

func (w WebLocalStorage) LoadSession(_ context.Context) (_ []byte, rerr error)

LoadSession loads session using Web Storage API.

func (WebLocalStorage) StoreSession added in v0.40.0

func (w WebLocalStorage) StoreSession(_ context.Context, data []byte) (rerr error)

StoreSession saves session using Web Storage API.

Jump to

Keyboard shortcuts

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