cache

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheCheckFailed = errors.New("phone cache: security check failed")

ErrCacheCheckFailed is returned when an operation is rejected due to a cache failure under FailClosed.

Functions

func HashIdentifier

func HashIdentifier(identifier string) string

HashIdentifier produces an opaque hex hash of sensitive identifiers (phone number, user ID) to prevent exposing plaintext phone numbers in cache keys or logs.

Types

type FailurePolicy

type FailurePolicy string

FailurePolicy defines how cache failures (e.g. timeout, partition) are handled for security controls.

const (
	// FailOpen allows operations when cache operations fail, prioritizing availability.
	FailOpen FailurePolicy = "fail_open"

	// FailClosed rejects operations when cache operations fail, prioritizing abuse mitigation.
	FailClosed FailurePolicy = "fail_closed"
)

type Limiter

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

Limiter manages rate limiting and cooldown periods for OTP requests.

func NewLimiter

func NewLimiter(c corecache.Cache, policy FailurePolicy, now func() time.Time) *Limiter

NewLimiter constructs a Limiter instance.

func (*Limiter) CheckAndSetCooldown

func (l *Limiter) CheckAndSetCooldown(ctx context.Context, phone string, cooldown time.Duration) (bool, error)

CheckAndSetCooldown checks whether a cooldown is currently active, activating it if not.

func (*Limiter) CheckRateLimit

func (l *Limiter) CheckRateLimit(ctx context.Context, phone string, maxRequests int, window time.Duration) (bool, error)

CheckRateLimit verifies whether requests for the given phone number are within the allowed limit.

Jump to

Keyboard shortcuts

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