framing

package
v0.0.0-...-1add468 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: BSD-2-Clause, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaximumSegmentLength is the length of the largest possible segment
	// including overhead.
	MaximumSegmentLength = 1500 - 52

	// LengthLength is the number of bytes used to represent length
	LengthLength = 2

	// TypeLength is the number of bytes used to indicate packet type
	TypeLength = 1

	ConsumeReadSize = MaximumSegmentLength * 16
)

Variables

View Source
var ErrAgain = errors.New("framing: More data needed to decode")

ErrAgain is the error returned when decoding requires more data to continue.

View Source
var ErrTagMismatch = errors.New("framing: Poly1305 tag mismatch")

Error returned when Decoder.Decode() failes to authenticate a frame.

Functions

func GenDrbg

func GenDrbg(key []byte) *drbg.HashDrbg

GenDrbg creates a *drbg.HashDrbg with some safety checks

Types

type BaseDecoder

type BaseDecoder struct {
	Drbg                  *drbg.HashDrbg
	LengthLength          int
	MinPayloadLength      int
	PacketOverhead        int
	MaxFramePayloadLength int

	NextLength        uint16
	NextLengthInvalid bool

	PayloadOverhead overheadFunc

	DecodeLength  decodeLengthfunc
	DecodePayload decodePayloadfunc
	ParsePacket   parsePacketFunc
	Cleanup       cleanupfunc

	ReceiveBuffer        *bytes.Buffer
	ReceiveDecodedBuffer *bytes.Buffer
	// contains filtered or unexported fields
}

func (*BaseDecoder) Decode

func (decoder *BaseDecoder) Decode(data []byte, frames *bytes.Buffer) (int, error)

Decode decodes a stream of data and returns the length if any. ErrAgain is a temporary failure, all other errors MUST be treated as fatal and the session aborted.

func (*BaseDecoder) GetFrame

func (decoder *BaseDecoder) GetFrame(frames *bytes.Buffer) (int, []byte, error)

func (*BaseDecoder) InitBuffers

func (decoder *BaseDecoder) InitBuffers()

func (*BaseDecoder) Read

func (decoder *BaseDecoder) Read(b []byte, conn net.Conn) (n int, err error)

type BaseEncoder

type BaseEncoder struct {
	Drbg                   *drbg.HashDrbg
	MaxPacketPayloadLength int
	LengthLength           int
	PayloadOverhead        overheadFunc

	Encode        encodeFunc
	ProcessLength processLengthFunc
	ChopPayload   chopPayloadFunc

	Type string
}

BaseEncoder implements the core encoder vars and functions

func (*BaseEncoder) Chop

func (encoder *BaseEncoder) Chop(b []byte, pktType uint8) (frameBuf bytes.Buffer, n int, err error)

Chop the pending data into payload frames.

func (*BaseEncoder) MakePacket

func (encoder *BaseEncoder) MakePacket(w io.Writer, payload []byte) error

type InvalidPacketLengthError

type InvalidPacketLengthError int

InvalidPacketLengthError is the error returned when decodePacket detects a invalid packet length/

func (InvalidPacketLengthError) Error

func (e InvalidPacketLengthError) Error() string

type InvalidPayloadLengthError

type InvalidPayloadLengthError int

InvalidPayloadLengthError is the error returned when Encoder.Encode() rejects the payload length.

func (InvalidPayloadLengthError) Error

Jump to

Keyboard shortcuts

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