codec

package
v0.3.63 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: LGPL-2.1 Imports: 12 Imported by: 1

Documentation

Index

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

type Authentication struct {
	HMAC hash.Hash
	// contains filtered or unexported fields
}

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) Decode

func (d *Decoder) Decode(data []byte, validation IValidation) (gtp.MsgPacket, int, error)

Decode 解码消息包

func (*Decoder) GC

func (d *Decoder) GC()

GC GC

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 NewEncoder added in v0.3.35

func NewEncoder() *Encoder

NewEncoder 创建消息包编码器

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 FetchNonce

type FetchNonce = generic.FuncPair0[[]byte, error] // 获取nonce值

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 创建加密模块

type IValidation added in v0.3.35

type IValidation interface {
	// Validate 验证消息包
	Validate(msgHead gtp.MsgHead, msgBuf []byte) error
}

IValidation 消息包验证模块

Jump to

Keyboard shortcuts

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