redis

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package redis provides Redis-backed implementations of the challenge store and key store interfaces for distributed deployments.

This package requires a Redis client to be passed in, giving you full control over connection pooling, timeouts, and clustering configuration.

Supported Redis clients:

  • github.com/redis/go-redis/v9
  • Any client implementing the Cmdable interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolCmd

type BoolCmd interface {
	Result() (bool, error)
}

BoolCmd is the interface for bool command results.

type ChallengeStore

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

ChallengeStore is a Redis-backed implementation of challenge.Store. Suitable for distributed deployments where multiple server instances need to share challenge state.

func NewChallengeStore

func NewChallengeStore(cfg ChallengeStoreConfig) (*ChallengeStore, error)

NewChallengeStore creates a new Redis-backed challenge store.

func (*ChallengeStore) Close

func (s *ChallengeStore) Close()

Close is a no-op for Redis store (connection is managed externally).

func (*ChallengeStore) Generate

func (s *ChallengeStore) Generate(identifier string) (string, error)

Generate creates a new challenge for the given identifier.

func (*ChallengeStore) Validate

func (s *ChallengeStore) Validate(identifier, challenge string) bool

Validate checks if the challenge is valid and consumes it. Returns true only if the challenge exists, matches, and hasn't expired.

type ChallengeStoreConfig

type ChallengeStoreConfig struct {
	// Client is the Redis client (required).
	Client Cmdable

	// KeyPrefix is prepended to all Redis keys (default: "attest:challenge:").
	KeyPrefix string

	// Timeout is how long challenges remain valid (default: 5 minutes).
	Timeout time.Duration

	// ChallengeBytes is the number of random bytes in a challenge (default: 32).
	ChallengeBytes int
}

ChallengeStoreConfig holds configuration for the Redis challenge store.

type Cmdable

type Cmdable interface {
	Get(ctx context.Context, key string) StringCmd
	Set(ctx context.Context, key string, value any, expiration time.Duration) StatusCmd
	SetNX(ctx context.Context, key string, value any, expiration time.Duration) BoolCmd
	Del(ctx context.Context, keys ...string) IntCmd
	Incr(ctx context.Context, key string) IntCmd
	HSet(ctx context.Context, key string, values ...any) IntCmd
	HGet(ctx context.Context, key, field string) StringCmd
	HGetAll(ctx context.Context, key string) MapStringStringCmd
	HIncrBy(ctx context.Context, key, field string, incr int64) IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) BoolCmd
}

Cmdable is the interface for Redis commands. This is compatible with github.com/redis/go-redis/v9.Client and ClusterClient.

type IntCmd

type IntCmd interface {
	Result() (int64, error)
}

IntCmd is the interface for int command results.

type KeyStore

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

KeyStore is a Redis-backed implementation of ios.KeyStore. Suitable for distributed deployments where multiple server instances need to share attestation state.

func NewKeyStore

func NewKeyStore(cfg KeyStoreConfig) (*KeyStore, error)

NewKeyStore creates a new Redis-backed key store.

func (*KeyStore) Delete

func (s *KeyStore) Delete(ctx context.Context, keyID string) error

Delete removes a public key by key ID.

func (*KeyStore) IncrementCounter

func (s *KeyStore) IncrementCounter(ctx context.Context, keyID string) (uint32, error)

IncrementCounter atomically increments and returns the new counter value.

func (*KeyStore) Load

func (s *KeyStore) Load(ctx context.Context, keyID string) (*ios.StoredKey, error)

Load retrieves a public key by key ID.

func (*KeyStore) Store

func (s *KeyStore) Store(ctx context.Context, keyID string, key *ios.StoredKey) error

Store saves a public key for the given key ID.

type KeyStoreConfig

type KeyStoreConfig struct {
	// Client is the Redis client (required).
	Client Cmdable

	// KeyPrefix is prepended to all Redis keys (default: "attest:key:").
	KeyPrefix string

	// TTL is how long keys are stored (default: 0 = no expiration).
	// Set this if you want keys to automatically expire.
	TTL time.Duration
}

KeyStoreConfig holds configuration for the Redis key store.

type MapStringStringCmd

type MapStringStringCmd interface {
	Result() (map[string]string, error)
}

MapStringStringCmd is the interface for map command results.

type StatusCmd

type StatusCmd interface {
	Err() error
}

StatusCmd is the interface for status command results.

type StringCmd

type StringCmd interface {
	Result() (string, error)
}

StringCmd is the interface for string command results.

Jump to

Keyboard shortcuts

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