Documentation
¶
Index ¶
- func CloseMsg32(f []byte, max uint) error
- func CloseMsgVI(f []byte, max uint) ([]byte, error)
- func NewMsg32(buf []byte) []byte
- func NewMsgVI(buf []byte) []byte
- func ReadMsg32(r io.Reader, buf []byte, max uint) ([]byte, error)
- func ReadMsgVI(r io.Reader, buf []byte, max uint) ([]byte, error)
- func Recv(r io.Reader, p encoding.BinaryUnmarshaler, m Message, buf []byte) (_ []byte, err error)
- func Send(w io.Writer, p encoding.BinaryAppender, m Message, buf []byte) (_ []byte, err error)
- type AESGCM
- type ALECMessenger
- type Cryptographer
- type Message
- type Messenger
- type Msg32
- type MsgVI
- type NewBuffers
- type PoolBuffers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseMsg32 ¶
CloseMsg32 finalizes a message to be sent. If max > 0 if is checked if the message payload exceeds a size of max byte and, in case, returns an error. In any case a message payload must no be greater than math.MaxUint32.
func NewMsg32 ¶
NewMsg32 prepares buf to be a new message or allocates a new message if buf is nil. After appending the payload to message one must call CloseMsg32 to be ready to send it.
func ReadMsg32 ¶
ReadMsg32 reads a message from r an place the payload into buf adjusting buf's size as necessary. If max > 0, it is checked that the payload size does not exceed max before reading the payload from r.
Types ¶
type AESGCM ¶
type AESGCM struct {
// contains filtered or unexported fields
}
func NewAESGCM ¶
The key argument must be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 as in aes.NewCipher.
type ALECMessenger ¶
type ALECMessenger struct {
// contains filtered or unexported fields
}
ALECMessenger (Application-Layer EnCryption Messenger) provides secure message exchange by adding encryption at the application layer. It wraps a Messenger and adds transparent encryption/decryption of messages using a provided Cryptographer implementation. This ensures message confidentiality while maintaining the underlying message boundary handling and buffer management of the base Messenger.
func NewALECMessenger ¶
func NewALECMessenger(c Cryptographer, m Message, b httputil.BufferPool) ALECMessenger
func (ALECMessenger) Recv ¶
func (alec ALECMessenger) Recv(r io.Reader, p encoding.BinaryUnmarshaler) (err error)
func (ALECMessenger) Send ¶
func (alec ALECMessenger) Send(w io.Writer, p encoding.BinaryAppender) (err error)
type Cryptographer ¶
type Message ¶
type Message interface {
// New prepares buf to hold a message to be sent. Actual data has to be
// appended to message. A message must be closed before sending.
New(buf []byte) (message []byte)
// Close closes the message and returns the send buffer as a subslice of
// message.
Close(message []byte) (send []byte, err error)
Read(r io.Reader, buf []byte) (data []byte, err error)
}
Message defines the interface for handling message boundaries on streaming connections in the rqre library.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger combines a Message implementation for handling message boundaries with a BufferPool for efficient buffer management to exchange messages on streaming connections.
func NewMessenger ¶
func NewMessenger(m Message, b httputil.BufferPool) Messenger
type Msg32 ¶
type Msg32 uint32
Msg32 handles messages with a 32-bit size field. If Msg32 > 0 message payload must not exceed that value.
type MsgVI ¶
type MsgVI uint
MsgVI implements Message with variable integer encoded message sizes. If MsgVI > 0, message payload must not exceed that value.
type NewBuffers ¶
type NewBuffers int
NewBuffers implements httputil.BufferPool by creating new byte slices for each Get() call. The integer value defines the capacity of created buffers. This implementation does not reuse buffers, making it suitable for cases where buffer reuse is not beneficial or when memory pressure is not a concern.
func (NewBuffers) Get ¶
func (b NewBuffers) Get() []byte
func (NewBuffers) Put ¶
func (b NewBuffers) Put([]byte)
type PoolBuffers ¶
type PoolBuffers struct {
// contains filtered or unexported fields
}
PoolBuffers implements httputil.BufferPool using a sync.Pool for efficient buffer reuse. This implementation reduces memory allocation overhead by recycling buffers, making it suitable for high-throughput scenarios or when memory pressure is a concern.
func NewPoolBuffers ¶
func NewPoolBuffers(init int) PoolBuffers
func (PoolBuffers) Get ¶
func (b PoolBuffers) Get() []byte
func (PoolBuffers) Put ¶
func (b PoolBuffers) Put(buf []byte)