fumitok

package module
v0.0.0-...-31ced65 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

README

fumitok

不微啄 - ALTERUM JWT FUMIAMAE

Documentation

Index

Constants

View Source
const (
	TokenLength = 88
)

Variables

View Source
var (
	ErrInvalidTokenKeySize = errors.New("invalid token key size")
	ErrExpiredToken        = errors.New("expired token")
	ErrInvalidToken        = errors.New("invalid token")
	ErrInvalidTokenLength  = errors.New("invalid token len")
)
View Source
var (
	ErrCipherTextTooShort = errors.New("ciphertext too short")
)

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString 没有内存开销的转换

func StringToBytes

func StringToBytes(s string) (b []byte)

StringToBytes 没有内存开销的转换

Types

type Tokenizer

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

Tokenizer xchacha20 对称加密密钥

func NewTokenizer

func NewTokenizer(hexkeystr string) (t Tokenizer, err error)

NewTokenizer ...

func (*Tokenizer) Generate

func (t *Tokenizer) Generate(id uint64, expireAt time.Time, addt, mask uint16) (string, error)

Generate 生成 token

  • id 用户标识符, 被加密
  • expireAt 有效期至
  • addt, mask 附加数据和其掩码, 不被加密

func (*Tokenizer) Refresh

func (t *Tokenizer) Refresh(
	token string, expireAt time.Time, validAfter time.Duration,
	mask uint16, checks ...func(uint16) error,
) (string, error)

Refresh 过期时刷新 token

  • token 旧 token
  • expireAt 新的过期时间
  • validAfter 旧 token 过期此时间段内仍可用于刷新
  • mask 附加数据之掩码
  • check 在解码前检查附加数据是否符合要求

func (*Tokenizer) Validate

func (t *Tokenizer) Validate(
	token string, mask uint16, checks ...func(uint16) error,
) (uint64, uint16, time.Time, error)

Validate 验证并提取信息

参数

  • token 待验证凭据
  • mask 附加数据之掩码, 将在返回时做掩模
  • check 在解码前检查附加数据是否符合要求

返回

  • uint64 用户标识符
  • uint16 附加数据

Jump to

Keyboard shortcuts

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