Documentation
¶
Index ¶
- Constants
- type Header
- type JwtConfig
- type Payload
- type SimplePayload
- type Subject
- func (self *Subject) AddHeader(config JwtConfig) *Subject
- func (self *Subject) Aud(aud string) *Subject
- func (self *Subject) CheckReady() bool
- func (self *Subject) Create(sub string) *Subject
- func (self *Subject) Dev(dev string) *Subject
- func (self *Subject) Expired(exp int64) *Subject
- func (self *Subject) Generate(config JwtConfig) string
- func (self *Subject) GetAud(b []byte) string
- func (self *Subject) GetDev(b []byte) string
- func (self *Subject) GetExp(b []byte) int64
- func (self *Subject) GetExt(b []byte) string
- func (self *Subject) GetIat(b []byte) int64
- func (self *Subject) GetIss(b []byte) string
- func (self *Subject) GetJti(b []byte) string
- func (self *Subject) GetSub(b []byte) string
- func (self *Subject) GetTokenSecret(token, secret string) []byte
- func (self *Subject) GetTokenSecretExtract(token, secret, kdfType, msgType string) []byte
- func (self *Subject) Iss(iss string) *Subject
- func (v Subject) MarshalEasyJSON(w *jwriter.Writer)
- func (v Subject) MarshalJSON() ([]byte, error)
- func (self *Subject) SetCache(cache cache.Cache)
- func (self *Subject) Signature(text, key string) string
- func (v *Subject) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *Subject) UnmarshalJSON(data []byte) error
- func (self *Subject) Verify(auth []byte, key string) error
Constants ¶
const ( JWT = "JWT" HS256 = "HS256" FIVE_MINUTES = int64(300) TWO_WEEK = int64(1209600) SubjectTokenSecret = "Subject-Token-Secret-V1" SubjectTokenVerify = "Subject-Token-Verify-V1" SubjectKDFSecret = "Subject-KDF-Secret-V1" SubjectKDFVerify = "Subject-KDF-Verify-V1" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
Alg string `json:"alg"` // 16字节 (8+8) - string字段
Typ string `json:"typ"` // 16字节 (8+8) - string字段
}
Header 结构体 - 32字节 (2个string,8字节对齐,无填充) 排列优化:string字段连续排列
func (Header) MarshalEasyJSON ¶ added in v1.1.0
MarshalEasyJSON supports easyjson.Marshaler interface
func (Header) MarshalJSON ¶ added in v1.1.0
MarshalJSON supports json.Marshaler interface
func (*Header) UnmarshalEasyJSON ¶ added in v1.1.0
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Header) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON supports json.Unmarshaler interface
type JwtConfig ¶
type JwtConfig struct {
TokenKey string // 16字节 (8+8)
TokenAlg string // 16字节 (8+8)
TokenTyp string // 16字节 (8+8)
TokenExp int64 // 8字节
}
JwtConfig 结构体 - 56字节 (4个字段,8字节对齐,无填充) 排列优化:int64放在最后,利用string的16字节对齐
type Payload ¶
type Payload struct {
// 16字节字段组 (6个string字段,96字节)
Sub string `json:"sub"` // 用户主体 - 16字节 (8+8)
Aud string `json:"aud"` // 接收token主体 - 16字节 (8+8)
Iss string `json:"iss"` // 签发token主体 - 16字节 (8+8)
Dev string `json:"dev"` // 设备类型,web/app - 16字节 (8+8)
Jti string `json:"jti"` // 唯一身份标识,主要用来作为一次性token,从而回避重放攻击 - 16字节 (8+8)
Ext string `json:"ext"` // 扩展信息 - 16字节 (8+8)
// 8字节字段组 (2个int64字段,16字节)
Iat int64 `json:"iat"` // 授权token时间 - 8字节
Exp int64 `json:"exp"` // 授权token过期时间 - 8字节
}
Payload 结构体 - 112字节 (8个字段,8字节对齐,无填充) 排列优化:string字段组在前(96字节),int64字段组在后(16字节)
func (Payload) MarshalEasyJSON ¶ added in v1.1.0
MarshalEasyJSON supports easyjson.Marshaler interface
func (Payload) MarshalJSON ¶ added in v1.1.0
MarshalJSON supports json.Marshaler interface
func (*Payload) UnmarshalEasyJSON ¶ added in v1.1.0
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Payload) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON supports json.Unmarshaler interface
type SimplePayload ¶ added in v1.1.0
SimplePayload 结构体 - 24字节 (string+int64,8字节对齐,无填充) 排列优化:int64放在string后面,利用8字节对齐
type Subject ¶
type Subject struct {
// 8字节指针字段组 (2个字段)
Header *Header // 8字节 - 指针字段
Payload *Payload // 8字节 - 指针字段
// contains filtered or unexported fields
}
Subject 结构体 - 32字节 (3个字段,8字节对齐,8字节填充) 排列优化:按字段类型分组,指针字段在前,接口字段在后
func (*Subject) CheckReady ¶ added in v1.0.104
func (*Subject) GetTokenSecret ¶
GetTokenSecret 最简单高效的派生密钥,因为token已经有足够的熵值
func (*Subject) GetTokenSecretExtract ¶ added in v1.1.3
GetTokenSecretExtract 最简单高效的派生密钥,因为token已经有足够的熵值
func (Subject) MarshalEasyJSON ¶ added in v1.1.0
MarshalEasyJSON supports easyjson.Marshaler interface
func (Subject) MarshalJSON ¶ added in v1.1.0
MarshalJSON supports json.Marshaler interface
func (*Subject) UnmarshalEasyJSON ¶ added in v1.1.0
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Subject) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON supports json.Unmarshaler interface