record

package
v0.0.0-...-11a1bd4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// we use 0 as "no alert" indicator
	AlerLevelWarning = 1
	AlerLevelFatal   = 2
)
View Source
const (
	RecordTypeAlert           = 21
	RecordTypeHandshake       = 22
	RecordTypeApplicationData = 23
	// PlaintextContentTypeHeartbeat       = 24 // [rfc6520] should not be received without negotiating extension. We choose to error on it.
	RecordTypeAck = 26
)
View Source
const AckElementSize = 16
View Source
const AckHeaderSize = 2
View Source
const AlertSize = 2
View Source
const MaxCiphertextRecordLength = MaxPlaintextRecordLength + 256 // [rfc8446:5.2]
View Source
const MaxPlaintextRecordLength = 16384 // [rfc8446:5.1]
View Source
const MaxSeq = 0xFFFFFFFFFFFF
View Source
const OutgoingCiphertextRecordHeader16 = 5 // first byte + 8-bit seqnum + 16-bit length
View Source
const OutgoingCiphertextRecordHeader8 = 4 // first byte + 16-bit seqnum + 16-bit length

This does not include CID size and AEAD seal, they are deterministic but depend on runtime parameters

View Source
const PlaintextRecordHeaderSize = 13

Variables

View Source
var ErrAckRecordWrongSize = errors.New("ack record size not multiple of 16")
View Source
var ErrAlertLevelParsing = errors.New("alert level failed to parse")
View Source
var ErrCiphertextRecordBodyTooLong = errors.New("cipher text record body exceeds 2^14 + 256")
View Source
var ErrCiphertextRecordTooShort = errors.New("cipher text record header too short")
View Source
var ErrCiphertextRecordTooShortLength = errors.New("cipher text record body too short (explicit length)")
View Source
var ErrPlaintextRecordBodyEpochNonZero = errors.New("plaintext record body non zero epoch")
View Source
var ErrPlaintextRecordBodyTooLong = errors.New("plaintext record body exceeds 2^14")
View Source
var ErrPlaintextRecordBodyTooShort = errors.New("plaintext record body too short")
View Source
var ErrPlaintextRecordHeaderTooShort = errors.New("plaintext record header too short")
View Source
var ErrPlaintextRecordWrongLegacyRecordVersion = errors.New("plaintext record wrong legacy record version")
View Source
var ErrRecordTypeFailedToParse = errors.New("record type failed to parse")

Functions

func CiphertextHeaderFirstByte

func CiphertextHeaderFirstByte(hasCID bool, has16bitSeqNum bool, hasLength bool, epoch uint16) byte

func IsEncryptedRecord

func IsEncryptedRecord(fb byte) bool

func RecordNumberCmp

func RecordNumberCmp(a, b Number) int

Types

type AckParser

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

func NewAckParser

func NewAckParser(recordBody []byte) (AckParser, error)

return by value to signal usage pattern

func (*AckParser) PopFront

func (p *AckParser) PopFront(epochSeqOverflowCounter *int) (rn Number, ok bool)

type Alert

type Alert struct {
	Level       byte
	Description byte
}

func AlertCloseNormal

func AlertCloseNormal() Alert

func (*Alert) IsFatal

func (msg *Alert) IsFatal() bool

func (*Alert) Parse

func (msg *Alert) Parse(body []byte) (err error)

func (*Alert) Write

func (msg *Alert) Write(body []byte) []byte

type Encrypted

type Encrypted struct {
	FirstByte byte
	CID       []byte // alias to original slice
	SeqNum    []byte // alias to original slice to be encrypted/decrypted in place
	Header    []byte // alias to original slice for AEAD
	// Length is checked, not stored
	Ciphertext []byte // alias to original slice
}

func (*Encrypted) ClosestSequenceNumber

func (hdr *Encrypted) ClosestSequenceNumber(seqNumData []byte, expectedSN uint64) (uint16, uint64)

func (*Encrypted) Epoch

func (hdr *Encrypted) Epoch() byte

func (*Encrypted) Has16BitSeqNum

func (hdr *Encrypted) Has16BitSeqNum() bool

func (*Encrypted) HasCID

func (hdr *Encrypted) HasCID() bool

func (*Encrypted) HasLength

func (hdr *Encrypted) HasLength() bool

func (*Encrypted) MatchesEpoch

func (hdr *Encrypted) MatchesEpoch(epoch uint16) bool

func (*Encrypted) Parse

func (hdr *Encrypted) Parse(datagram []byte, cIDLength int) (n int, err error)

type Number

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

func NumberWith

func NumberWith(epoch uint16, seqNum uint64) Number

func (Number) Epoch

func (r Number) Epoch() uint16

func (Number) Less

func (r Number) Less(other Number) bool

func (Number) SeqNum

func (r Number) SeqNum() uint64

type Plaintext

type Plaintext struct {
	ContentType byte
	// Version is fixed, not stored
	// epoch is fixed to 0 for plaintext messages, do not store
	SequenceNumber uint64 // stored as 48-bit
	// Length is checked, not stored
	// Body is alias to buffer which must be parsed/saved and never retained
	Body []byte
}

func (*Plaintext) Parse

func (hdr *Plaintext) Parse(datagram []byte) (n int, err error)

type PlaintextHeader

type PlaintextHeader struct {
	ContentType byte
	// Version is fixed, not stored
	// epoch is fixed to 0 for plaintext messages, do not store
	SequenceNumber uint64 // stored as 48-bit

}

func (*PlaintextHeader) Write

func (hdr *PlaintextHeader) Write(datagram []byte, length uint16) []byte

Jump to

Keyboard shortcuts

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