Documentation
¶
Index ¶
Constants ¶
const ( // All package errors are wrapping Error Error = errorFlag("session: error") ErrKeyExpired = errorFlag("session: key expired") ErrKeyTampered = errorFlag("session: key tampered") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a scaled monotonic clock. It increments time by 1 every step nanoseconds.
type KeyFactory ¶
type KeyFactory[K comparable] interface { New(ad uint64) K Check(key K) error }
type MemStore ¶
type MemStore[K TimedKey, V any] struct { KeyFacto KeyFactory[K] // contains filtered or unexported fields }
MemStore is an in memory session Store that automatically expires keys.
func NewMemStore ¶
func NewMemStore[K TimedKey, V any](kf KeyFactory[K]) (*MemStore[K, V], error)
NewMemStore instantiates a new MemStore. It errors if kf is nil.
func (*MemStore[K, V]) Get ¶
Get returns the value indexed by key. The bool flag is true if the key exists in the MemStore.
func (*MemStore[K, V]) Pop ¶
Pop removes the key from the MemStore and returns the associated value. The bool flag is true if the key was found in the MemStore.
type Sid ¶
type Sid [sidSize]byte
Sid is a byte array used as session identifier. Sid bytes encode [mac|timestamp|counter|data]
type SidFactory ¶
type SidFactory struct {
// contains filtered or unexported fields
}
SidFactory generates unique Sids. It can check time validity and origin of Sid values.
func NewSidFactory ¶
func NewSidFactory(lifetime time.Duration) (*SidFactory, error)
NewSidFactory instantiates a SidFactory. Generated Sid expires after lifetime. NewSidFactory errors if lifetime is invalid.
func (*SidFactory) Check ¶
func (self *SidFactory) Check(sid Sid) error
Check errors if sid was not generated by the SidFactory or if sid has expired.
func (*SidFactory) New ¶
func (self *SidFactory) New(ad uint64) Sid
New returns a new Sid different from Sid returned by previous calls.
type TimedKey ¶
type TimedKey interface {
comparable
Timed
}