Documentation
¶
Index ¶
- Constants
- Variables
- type KV
- func (k *KV) Close()
- func (k *KV) Consume(ctx context.Context, key string) ([]byte, bool, error)
- func (k *KV) Del(ctx context.Context, key string) error
- func (k *KV) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (k *KV) Incr(ctx context.Context, key string, ttl time.Duration) (int64, error)
- func (k *KV) Len() int
- func (k *KV) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- type KVOption
- type SIWSCache
- func (c *SIWSCache) Close() error
- func (c *SIWSCache) Consume(ctx context.Context, nonce string) (siws.ChallengeData, bool, error)
- func (c *SIWSCache) Del(ctx context.Context, nonce string) error
- func (c *SIWSCache) Get(ctx context.Context, nonce string) (siws.ChallengeData, bool, error)
- func (c *SIWSCache) Put(ctx context.Context, nonce string, data siws.ChallengeData) error
- type SIWSCacheOption
- type StateCache
- func (s *StateCache) Close() error
- func (s *StateCache) Consume(ctx context.Context, state string) (oidckit.StateData, bool, error)
- func (s *StateCache) Del(ctx context.Context, state string) error
- func (s *StateCache) Get(ctx context.Context, state string) (oidckit.StateData, bool, error)
- func (s *StateCache) Put(ctx context.Context, state string, v oidckit.StateData) error
Constants ¶
const ( DefaultKVSweepInterval = time.Minute DefaultKVMaxEntries = 100_000 )
Variables ¶
var ErrKVFull = errors.New("memorystore: kv entry cap reached")
ErrKVFull is returned by Set when the store holds MaxEntries live keys and sweeping expired ones frees nothing: the bound on heap growth is a hard refusal, never a silent eviction of someone else's live token.
Functions ¶
This section is empty.
Types ¶
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV is an in-memory key-value store with TTL support for single-process deployments. Expired entries are reclaimed by a background sweep (#305) as well as on access, and the live entry count is capped.
func (*KV) Close ¶ added in v0.98.0
func (k *KV) Close()
Close stops the background sweep. Idempotent.
func (*KV) Consume ¶
Consume atomically returns and deletes a key under a single lock hold, so a value is delivered to AT MOST ONE caller even under concurrent reads — the in-memory analogue of Redis GETDEL. Required for single-use credentials whose KEY is the secret (passkey challenge, password-reset token); a Get+Del pair would let two concurrent requests both observe the value before either deletes. Missing or expired key => (nil, false, nil).
func (*KV) Incr ¶ added in v0.98.0
Incr is the in-memory analogue of the Redis INCR+PEXPIRE script: read, increment and write happen under one lock hold, so concurrent callers see distinct consecutive values. The TTL is set only when the key is created, and creation is bounded by the entry cap exactly like Set.
type KVOption ¶ added in v0.98.0
type KVOption func(*KV)
func WithKVClock ¶ added in v0.98.0
WithKVClock replaces the TTL clock (tests advance it instead of sleeping).
func WithMaxEntries ¶ added in v0.98.0
WithMaxEntries caps the number of live entries; Set refuses beyond it.
func WithSweepInterval ¶ added in v0.98.0
WithSweepInterval sets how often expired entries are reclaimed without being read. Non-positive disables the sweep.
type SIWSCache ¶
type SIWSCache struct {
// contains filtered or unexported fields
}
SIWSCache stores pending SIWS challenges in memory. This is only suitable for single-node deployments or local development.
func NewSIWSCache ¶
func NewSIWSCache(ttl time.Duration, opts ...SIWSCacheOption) *SIWSCache
NewSIWSCache creates a new in-memory SIWS challenge cache.
func (*SIWSCache) Close ¶
Close stops the background cleanup goroutine. Should be called when the cache is no longer needed.
func (*SIWSCache) Consume ¶
Consume atomically retrieves and deletes a challenge (single-use). The write lock makes get+delete a single-winner operation, so two concurrent callers presenting the same nonce can't both verify — closing the SIWS replay window.
type SIWSCacheOption ¶ added in v0.98.0
type SIWSCacheOption func(*SIWSCache)
func WithSIWSCacheClock ¶ added in v0.98.0
func WithSIWSCacheClock(now func() time.Time) SIWSCacheOption
WithSIWSCacheClock replaces the TTL clock (tests advance it instead of sleeping).
type StateCache ¶
type StateCache struct {
// contains filtered or unexported fields
}
StateCache is an in-memory implementation of oidckit.StateCache with TTL.
func NewStateCache ¶
func NewStateCache(ttl time.Duration) *StateCache
NewStateCache creates a new in-memory state cache with the given TTL. If ttl <= 0, a default of 10 minutes is used. Starts a background goroutine to clean up expired entries every minute.
func (*StateCache) Close ¶
func (s *StateCache) Close() error
Close stops the background cleanup goroutine. Should be called when the cache is no longer needed.
func (*StateCache) Consume ¶
Consume atomically returns and deletes the state in one locked step, closing the replay/TOCTOU window a separate Get+Del leaves open. ok=false if the state is absent, expired, or already consumed.