nonce

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

@Author daixk 2025/12/22 15:56:00

@Author daixk 2025/12/22 15:56:00

Index

Constants

View Source
const (
	// DefaultNonceTTL stores default nonce ttl DefaultNonceTTL 存储默认 nonce 过期时间
	DefaultNonceTTL = 5 * time.Minute
	// NonceLength stores nonce byte length NonceLength 存储 Nonce 字节长度
	NonceLength = 32
	// NonceKeySuffix stores nonce key suffix NonceKeySuffix 存储 Nonce 键后缀
	NonceKeySuffix = "nonce:"
)
View Source
const (
	// DefaultRefreshTTL stores default refresh ttl DefaultRefreshTTL 存储默认刷新令牌过期时间
	DefaultRefreshTTL = 30 * 24 * time.Hour
	// DefaultAccessTTL stores default access ttl DefaultAccessTTL 存储默认访问令牌过期时间
	DefaultAccessTTL = 2 * time.Hour
	// RefreshTokenLength stores refresh token length RefreshTokenLength 存储刷新令牌字节长度
	RefreshTokenLength = 32
	// RefreshKeySuffix stores refresh key suffix RefreshKeySuffix 存储刷新令牌键后缀
	RefreshKeySuffix = "refresh:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// TTL stores nonce default ttl TTL 存储 Nonce 默认有效期
	TTL time.Duration
}

Config defines nonce manager config Config 定义 Nonce 管理器配置

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default nonce config DefaultConfig 返回默认 Nonce 配置

func (*Config) Clone

func (c *Config) Clone() *Config

Clone returns a deep copy of nonce config Clone 克隆 Nonce 配置

func (*Config) Validate

func (c *Config) Validate() error

Validate validates nonce config Validate 验证 Nonce 配置

type NonceManager

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

NonceManager defines nonce manager NonceManager 定义 Nonce 管理器

func NewDefaultNonceManager

func NewDefaultNonceManager(authType, prefix string, storage adapter.Storage) *NonceManager

NewDefaultNonceManager creates nonce manager with default config NewDefaultNonceManager 使用默认配置创建 Nonce 管理器

func NewNonceManager

func NewNonceManager(authType, prefix string, storage adapter.Storage, ttl time.Duration) *NonceManager

NewNonceManager creates nonce manager NewNonceManager 创建新的 Nonce 管理器

func NewNonceManagerWithConfig

func NewNonceManagerWithConfig(authType, prefix string, storage adapter.Storage, cfg *Config) *NonceManager

NewNonceManagerWithConfig creates nonce manager with config NewNonceManagerWithConfig 使用配置创建 Nonce 管理器

func (*NonceManager) Generate

func (nm *NonceManager) Generate(ctx context.Context) (string, error)

Generate creates nonce with default ttl Generate 使用默认有效期生成并存储 nonce

func (*NonceManager) GenerateWithTimeout

func (nm *NonceManager) GenerateWithTimeout(ctx context.Context, timeout time.Duration) (string, error)

GenerateWithTimeout creates nonce with timeout GenerateWithTimeout 使用指定有效期生成并存储 nonce

func (*NonceManager) GetTTL

func (nm *NonceManager) GetTTL(ctx context.Context, nonce string) (int64, error)

GetTTL gets remaining nonce ttl GetTTL 获取 nonce 的剩余有效时间秒数

func (*NonceManager) IsValid

func (nm *NonceManager) IsValid(ctx context.Context, nonce string) bool

IsValid checks nonce without consuming IsValid 检查 nonce 是否有效且不消费

func (*NonceManager) Verify

func (nm *NonceManager) Verify(ctx context.Context, nonce string) bool

Verify verifies and consumes nonce Verify 验证并消费 nonce 且在不存在时返回 false

func (*NonceManager) VerifyAndConsume

func (nm *NonceManager) VerifyAndConsume(ctx context.Context, nonce string) error

VerifyAndConsume verifies nonce with error VerifyAndConsume 验证并消费 nonce 且在无效时返回错误

Jump to

Keyboard shortcuts

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