cryptocodec

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadLength    = 4
	MaxPacketSize = 64 * 1024 * 1024
)

Variables

View Source
var (
	ErrPacketSizeExcced   = errors.New("codec: packet size exceed")
	ErrWrongMessageType   = errors.New("codec: wrong message type")
	ErrInvalidMessage     = errors.New("codec: invalid message")
	ErrInvalidRouteLength = errors.New("codec: invalid route length")
)

Functions

This section is empty.

Types

type AESGCMCrypto added in v1.2.0

type AESGCMCrypto struct{}

func (*AESGCMCrypto) Decrypt added in v1.2.0

func (*AESGCMCrypto) Decrypt(ciphertext, key []byte) ([]byte, error)

func (*AESGCMCrypto) Encrypt added in v1.2.0

func (aesgcm *AESGCMCrypto) Encrypt(plaintext, key []byte) ([]byte, error)

func (*AESGCMCrypto) EncryptWithNonce added in v1.2.0

func (*AESGCMCrypto) EncryptWithNonce(plaintext, key []byte, nonce []byte) ([]byte, error)

func (*AESGCMCrypto) String added in v1.2.0

func (*AESGCMCrypto) String() string

type Codec

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

func NewCodec

func NewCodec(base64Key string) *Codec

func (*Codec) Entity

func (c *Codec) Entity(dictionary message.Dictionary) codec.CodecEntity

type CodecEntity

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

func NewCodecEntity

func NewCodecEntity(dictionary message.Dictionary, cryptoKey []byte) *CodecEntity

func (*CodecEntity) DecodeMessage

func (c *CodecEntity) DecodeMessage(data []byte) (*message.Message, error)

func (*CodecEntity) DecodeMessageRaw added in v1.2.0

func (c *CodecEntity) DecodeMessageRaw(data []byte) (*message.Message, error)

func (*CodecEntity) DecodeMessageWithDetection added in v1.2.0

func (c *CodecEntity) DecodeMessageWithDetection(data []byte) (*message.Message, error)

func (*CodecEntity) DecodePacket

func (c *CodecEntity) DecodePacket(data []byte) ([]*packet.Packet, error)

func (*CodecEntity) EncodeMessage

func (c *CodecEntity) EncodeMessage(m *message.Message) ([]byte, error)

func (*CodecEntity) EncodePacket

func (c *CodecEntity) EncodePacket(packets []*packet.Packet) ([]byte, error)

func (*CodecEntity) String added in v1.1.49

func (c *CodecEntity) String() string

type Crypto added in v1.1.3

type Crypto interface {
	fmt.Stringer
	Encrypt(plaintext, key []byte) ([]byte, error)
	Decrypt(ciphertext, key []byte) ([]byte, error)
}

type CryptoEntity added in v1.2.0

type CryptoEntity struct {
	Key    []byte
	Crypto Crypto
}

func NewCryptoEntity added in v1.2.0

func NewCryptoEntity(key []byte, crypto Crypto) *CryptoEntity

func (*CryptoEntity) Decrypt added in v1.2.0

func (c *CryptoEntity) Decrypt(data []byte) ([]byte, error)

func (*CryptoEntity) Encrypt added in v1.2.0

func (c *CryptoEntity) Encrypt(data []byte) ([]byte, error)

type CryptoType added in v1.2.0

type CryptoType uint32
const (
	AESGCM CryptoType = iota
	XOR
	Plain
	Unknown
)

func (CryptoType) Crypto added in v1.2.0

func (c CryptoType) Crypto() Crypto

func (CryptoType) Decrypt added in v1.2.0

func (c CryptoType) Decrypt(ciphertext, key []byte) ([]byte, error)

func (CryptoType) Encrypt added in v1.2.0

func (c CryptoType) Encrypt(plaintext, key []byte) ([]byte, error)

func (CryptoType) String added in v1.2.0

func (c CryptoType) String() string

type PlainCrypto added in v1.2.0

type PlainCrypto struct{}

func (*PlainCrypto) Decrypt added in v1.2.0

func (*PlainCrypto) Decrypt(ciphertext, key []byte) ([]byte, error)

func (*PlainCrypto) Encrypt added in v1.2.0

func (*PlainCrypto) Encrypt(plaintext, key []byte) ([]byte, error)

func (*PlainCrypto) String added in v1.2.0

func (*PlainCrypto) String() string

type XORCrypto added in v1.2.0

type XORCrypto struct{}

func (*XORCrypto) Decrypt added in v1.2.0

func (*XORCrypto) Decrypt(ciphertext, key []byte) ([]byte, error)

func (*XORCrypto) Encrypt added in v1.2.0

func (*XORCrypto) Encrypt(plaintext, key []byte) ([]byte, error)

func (*XORCrypto) String added in v1.2.0

func (*XORCrypto) String() string

Jump to

Keyboard shortcuts

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