codec

package
v0.3.47 Latest Latest
Warning

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

Go to latest
Published: May 18, 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")                                                    // 解码错误
	ErrUnableToDetectLength = fmt.Errorf("%w: %w, unable to detect length", ErrDecode, io.ErrShortBuffer) // 无法探测消息长度
)
View Source
var (
	ErrMAC          = errors.New("gtp-mac")                   // MAC错误
	ErrIncorrectMAC = fmt.Errorf("%w: incorrect MAC", ErrMAC) // 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 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     // 加密模块
	MAC         IMAC            // MAC模块
	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) 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 设置加密模块

func (*Decoder) SetMAC added in v0.3.35

func (d *Decoder) SetMAC(mac IMAC) *Decoder

SetMAC 设置MAC模块

type Encoder

type Encoder struct {
	Encryption     IEncryption  // 加密模块
	MAC            IMAC         // MAC模块
	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.MsgReader) (ret binaryutil.RecycleBytes, err error)

Encode 编码消息包

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 设置加密模块

func (*Encoder) SetMAC added in v0.3.35

func (e *Encoder) SetMAC(mac IMAC) *Encoder

SetMAC 设置MAC模块

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

type IMAC interface {
	// PatchMAC 补充MAC
	PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
	// VerifyMAC 验证MAC
	VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)
	// SizeofMAC MAC大小
	SizeofMAC(msgLen int) int
}

IMAC MAC模块接口

func NewMAC added in v0.3.35

func NewMAC(h hash.Hash, pk []byte) IMAC

NewMAC 创建MAC模块

func NewMAC32 added in v0.3.35

func NewMAC32(h hash.Hash32, pk []byte) IMAC

NewMAC32 创建MAC32模块

func NewMAC64 added in v0.3.35

func NewMAC64(h hash.Hash64, pk []byte) IMAC

NewMAC64 创建MAC64模块

type IValidation added in v0.3.35

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

IValidation 消息包验证模块

type MAC added in v0.3.35

type MAC struct {
	Hash       hash.Hash // hash函数
	PrivateKey []byte    // 秘钥
}

MAC MAC模块

func (*MAC) PatchMAC added in v0.3.35

func (m *MAC) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MAC) SizeofMAC added in v0.3.35

func (m *MAC) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MAC) VerifyMAC added in v0.3.35

func (m *MAC) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

type MAC32 added in v0.3.35

type MAC32 struct {
	Hash       hash.Hash32 // hash(32bit)函数
	PrivateKey []byte      // 秘钥
}

MAC32 MAC32模块

func (*MAC32) PatchMAC added in v0.3.35

func (m *MAC32) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MAC32) SizeofMAC added in v0.3.35

func (m *MAC32) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MAC32) VerifyMAC added in v0.3.35

func (m *MAC32) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

type MAC64 added in v0.3.35

type MAC64 struct {
	Hash       hash.Hash64 // hash(64bit)函数
	PrivateKey []byte      // 秘钥
}

MAC64 MAC64模块

func (*MAC64) PatchMAC added in v0.3.35

func (m *MAC64) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MAC64) SizeofMAC added in v0.3.35

func (m *MAC64) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MAC64) VerifyMAC added in v0.3.35

func (m *MAC64) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

Jump to

Keyboard shortcuts

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