Documentation
¶
Index ¶
- Variables
- type Authentication
- type Compression
- type Decoder
- func (d *Decoder) Decode(data []byte, validation IValidation) (gtp.MsgPacket, int, error)
- func (d *Decoder) GC()
- func (d *Decoder) SetAuthentication(authentication IAuthentication) *Decoder
- func (d *Decoder) SetCompression(compression ICompression) *Decoder
- func (d *Decoder) SetEncryption(encryption IEncryption) *Decoder
- type Encoder
- func (e *Encoder) Encode(flags gtp.Flags, msg gtp.ReadableMsg) (ret binaryutil.RecycleBytes, err error)
- func (e *Encoder) SetAuthentication(authentication IAuthentication) *Encoder
- func (e *Encoder) SetCompression(compression ICompression, compressionMin int) *Encoder
- func (e *Encoder) SetEncryption(encryption IEncryption) *Encoder
- type Encryption
- type FetchNonce
- type IAuthentication
- type ICompression
- type IEncryption
- type IValidation
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDecode = errors.New("gtp-decode") // 解码错误 ErrUnableToPeekLength = fmt.Errorf("%w: %w, unable to peek length", ErrDecode, io.ErrShortBuffer) // 无法探测消息长度 )
View Source
var ( ErrAuthenticate = errors.New("gtp-authenticate") // 认证错误 ErrInvalidMAC = fmt.Errorf("%w: invalid MAC", ErrAuthenticate) // 错误的MAC )
View Source
var (
ErrCompress = errors.New("gtp-compress") // 压缩错误
)
View Source
var (
ErrEncode = errors.New("gtp-encode") // 编码错误
)
View Source
var (
ErrEncrypt = errors.New("gtp-encrypt") // 加密错误
)
Functions ¶
This section is empty.
Types ¶
type Authentication ¶ added in v0.3.63
Authentication 认证模块
func (*Authentication) Auth ¶ added in v0.3.63
func (m *Authentication) Auth(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)
Auth 认证
func (*Authentication) Sign ¶ added in v0.3.63
func (m *Authentication) Sign(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
Sign 签名
func (*Authentication) SizeOfAddition ¶ added in v0.3.63
func (m *Authentication) SizeOfAddition(msgLen int) (int, error)
SizeOfAddition 附加数据大小
type Compression ¶ added in v0.3.35
type Compression struct {
CompressionStream method.CompressionStream // 压缩流
}
Compression 压缩模块
func (*Compression) Compress ¶ added in v0.3.35
func (c *Compression) Compress(src []byte) (dst binaryutil.RecycleBytes, compressed bool, err error)
Compress 压缩数据
func (*Compression) Uncompress ¶ added in v0.3.35
func (c *Compression) Uncompress(src []byte) (dst binaryutil.RecycleBytes, err error)
Uncompress 解压缩数据
type Decoder ¶
type Decoder struct {
MsgCreator gtp.IMsgCreator // 消息对象构建器
Encryption IEncryption // 加密模块
Authentication IAuthentication // 认证模块
Compression ICompression // 压缩模块
// contains filtered or unexported fields
}
Decoder 消息包解码器
func NewDecoder ¶ added in v0.3.35
func NewDecoder(msgCreator gtp.IMsgCreator) *Decoder
NewDecoder 创建消息包解码器
func (*Decoder) SetAuthentication ¶ added in v0.3.63
func (d *Decoder) SetAuthentication(authentication IAuthentication) *Decoder
SetAuthentication 设置认证模块
func (*Decoder) SetCompression ¶ added in v0.3.35
func (d *Decoder) SetCompression(compression ICompression) *Decoder
SetCompression 设置压缩模块
func (*Decoder) SetEncryption ¶ added in v0.3.35
func (d *Decoder) SetEncryption(encryption IEncryption) *Decoder
SetEncryption 设置加密模块
type Encoder ¶
type Encoder struct {
Encryption IEncryption // 加密模块
Authentication IAuthentication // 认证模块
Compression ICompression // 压缩模块
CompressionMin int // 启用压缩阀值(字节),<=0表示不开启
}
Encoder 消息包编码器
func (*Encoder) Encode ¶
func (e *Encoder) Encode(flags gtp.Flags, msg gtp.ReadableMsg) (ret binaryutil.RecycleBytes, err error)
Encode 编码消息包
func (*Encoder) SetAuthentication ¶ added in v0.3.63
func (e *Encoder) SetAuthentication(authentication IAuthentication) *Encoder
SetAuthentication 设置认证模块
func (*Encoder) SetCompression ¶ added in v0.3.35
func (e *Encoder) SetCompression(compression ICompression, compressionMin int) *Encoder
SetCompression 设置压缩模块
func (*Encoder) SetEncryption ¶ added in v0.3.35
func (e *Encoder) SetEncryption(encryption IEncryption) *Encoder
SetEncryption 设置加密模块
type Encryption ¶ added in v0.3.35
type Encryption struct {
Cipher method.Cipher // 对称密码算法
Padding method.Padding // 填充方案
FetchNonce FetchNonce // 获取nonce值
}
Encryption 加密模块
func (*Encryption) SizeOfAddition ¶ added in v0.3.35
func (e *Encryption) SizeOfAddition(msgLen int) (int, error)
SizeOfAddition 附加数据大小
func (*Encryption) Transforming ¶ added in v0.3.35
func (e *Encryption) Transforming(dst, src []byte) (ret binaryutil.RecycleBytes, err error)
Transforming 变换数据
type IAuthentication ¶ added in v0.3.63
type IAuthentication interface {
// Sign 签名
Sign(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
// Auth 认证
Auth(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)
// SizeOfAddition 附加数据大小
SizeOfAddition(msgLen int) (int, error)
}
IAuthentication 认证模块接口,用于防止消息被篡改
func NewAuthentication ¶ added in v0.3.63
func NewAuthentication(hmac hash.Hash) IAuthentication
NewAuthentication 创建认证模块
type ICompression ¶ added in v0.3.35
type ICompression interface {
// Compress 压缩数据
Compress(src []byte) (dst binaryutil.RecycleBytes, compressed bool, err error)
// Uncompress 解压缩数据
Uncompress(src []byte) (dst binaryutil.RecycleBytes, err error)
}
ICompression 压缩模块接口
func NewCompression ¶ added in v0.3.35
func NewCompression(cs method.CompressionStream) ICompression
NewCompression 创建压缩模块
type IEncryption ¶ added in v0.3.35
type IEncryption interface {
// Transforming 变换数据
Transforming(dst, src []byte) (binaryutil.RecycleBytes, error)
// SizeOfAddition 附加数据大小
SizeOfAddition(msgLen int) (int, error)
}
IEncryption 加密模块接口
func NewEncryption ¶ added in v0.3.35
func NewEncryption(cipher method.Cipher, padding method.Padding, fetchNonce FetchNonce) IEncryption
NewEncryption 创建加密模块
Click to show internal directories.
Click to hide internal directories.