Documentation
¶
Overview ¶
Package recordlayer frames, inspects, and encodes DTLS wire records.
Index ¶
- Constants
- Variables
- func MarshalCiphertext(config CiphertextConfig, ciphertext []byte) ([]byte, error)
- func MarshalInnerPlaintext(content []byte, contentType protocol.ContentType, padding int) ([]byte, error)
- func MarshalRecord(config RecordConfig, payload []byte) ([]byte, error)
- func ParseInnerPlaintext(raw []byte) (content []byte, contentType protocol.ContentType, padding int, err error)
- func UnpackDatagram(datagram []byte, config UnpackDatagramConfig) (records [][]byte, err error)
- type CiphertextConfig
- type ParsedRecord
- func (r ParsedRecord) ConnectionID() []byte
- func (r ParsedRecord) ContentType() protocol.ContentType
- func (r ParsedRecord) Epoch() uint16
- func (r ParsedRecord) EpochLow() uint8
- func (r ParsedRecord) HeaderBytes() []byte
- func (r ParsedRecord) IsUnified() bool
- func (r ParsedRecord) LengthPresent() bool
- func (r ParsedRecord) Payload() []byte
- func (r ParsedRecord) Raw() []byte
- func (r ParsedRecord) SequenceBytes() int
- func (r ParsedRecord) SequenceNumber() uint64
- func (r ParsedRecord) Version() protocol.Version
- type RecordConfig
- type UnpackDatagramConfig
Examples ¶
Constants ¶
const ( // FixedHeaderSize is the fixed record header size without a CID. FixedHeaderSize = recordwire.FixedHeaderSize // MaxSequenceNumber is the largest sequence number in a fixed record header. MaxSequenceNumber = recordwire.MaxSequenceNumber )
Variables ¶
var ErrInvalidPacketLength = dtlserrors.ErrInvalidPacketLength
ErrInvalidPacketLength is returned when the packet length too small or declared length do not match.
Functions ¶
func MarshalCiphertext ¶
func MarshalCiphertext(config CiphertextConfig, ciphertext []byte) ([]byte, error)
MarshalCiphertext encodes one unified record with the selected C/S/L layout. It derives the length.
func MarshalInnerPlaintext ¶
func MarshalInnerPlaintext(content []byte, contentType protocol.ContentType, padding int) ([]byte, error)
MarshalInnerPlaintext returns owned content || contentType || zero padding.
func MarshalRecord ¶
func MarshalRecord(config RecordConfig, payload []byte) ([]byte, error)
MarshalRecord encodes one fixed-header record, deriving its payload length.
func ParseInnerPlaintext ¶
func ParseInnerPlaintext(raw []byte) (content []byte, contentType protocol.ContentType, padding int, err error)
ParseInnerPlaintext returns borrowed content.
func UnpackDatagram ¶
func UnpackDatagram(datagram []byte, config UnpackDatagramConfig) (records [][]byte, err error)
UnpackDatagram returns borrowed records from a datagram.
Types ¶
type CiphertextConfig ¶
type CiphertextConfig struct {
EpochLow uint8
SequenceNumber uint16
TwoByteSequence bool
ConnectionID []byte
LengthPresent bool
}
CiphertextConfig selects unified record wire fields. SequenceNumber is the wire value (masked for protected traffic). A record without LengthPresent must be last in its datagram.
type ParsedRecord ¶
type ParsedRecord struct {
// contains filtered or unexported fields
}
ParsedRecord borrows its input. Keep it unchanged while using returned slices.
func ParseRecord ¶
func ParseRecord(raw []byte, cidLength int) (ParsedRecord, error)
ParseRecord parses exactly one fixed or unified record with an explicit CID length.
Example ¶
package main
import (
"fmt"
"github.com/pion/dtls/v4/pkg/protocol"
"github.com/pion/dtls/v4/pkg/protocol/recordlayer"
)
func main() {
raw, err := recordlayer.MarshalRecord(recordlayer.RecordConfig{ContentType: protocol.ContentTypeHandshake, Version: protocol.Version1_2}, []byte{1, 2, 3})
if err != nil {
panic(err)
}
records, err := recordlayer.UnpackDatagram(raw, recordlayer.UnpackDatagramConfig{})
if err != nil {
panic(err)
}
record, err := recordlayer.ParseRecord(records[0], 0)
if err != nil {
panic(err)
}
fmt.Printf("epoch=%d sequence=%d payload=%x\n", record.Epoch(), record.SequenceNumber(), record.Payload())
}
Output: epoch=0 sequence=0 payload=010203
func (ParsedRecord) ConnectionID ¶
func (r ParsedRecord) ConnectionID() []byte
ConnectionID returns the borrowed CID, or nil when absent.
func (ParsedRecord) ContentType ¶
func (r ParsedRecord) ContentType() protocol.ContentType
ContentType returns the fixed header's outer type, or zero for unified records.
func (ParsedRecord) Epoch ¶
func (r ParsedRecord) Epoch() uint16
Epoch returns the fixed header's epoch, or zero for unified records.
func (ParsedRecord) EpochLow ¶
func (r ParsedRecord) EpochLow() uint8
EpochLow returns the two epoch bits of a unified header, or zero otherwise.
func (ParsedRecord) HeaderBytes ¶
func (r ParsedRecord) HeaderBytes() []byte
HeaderBytes returns the exact borrowed header, including masked sequence bytes.
func (ParsedRecord) IsUnified ¶
func (r ParsedRecord) IsUnified() bool
IsUnified reports whether this is a DTLS 1.3 unified header.
func (ParsedRecord) LengthPresent ¶
func (r ParsedRecord) LengthPresent() bool
LengthPresent reports whether the wire header carries an explicit length.
func (ParsedRecord) Payload ¶
func (r ParsedRecord) Payload() []byte
Payload returns the borrowed fragment or ciphertext.
func (ParsedRecord) Raw ¶
func (r ParsedRecord) Raw() []byte
Raw returns the exact borrowed wire record.
func (ParsedRecord) SequenceBytes ¶
func (r ParsedRecord) SequenceBytes() int
SequenceBytes returns the wire sequence width (6, 2, or 1), or 0 when empty.
func (ParsedRecord) SequenceNumber ¶
func (r ParsedRecord) SequenceNumber() uint64
SequenceNumber returns the fixed sequence or masked truncated unified sequence.
func (ParsedRecord) Version ¶
func (r ParsedRecord) Version() protocol.Version
Version returns the fixed header's wire version, or zero for unified records.
type RecordConfig ¶
type RecordConfig struct {
ContentType protocol.ContentType
Version protocol.Version
Epoch uint16
SequenceNumber uint64
ConnectionID []byte
}
RecordConfig selects fixed-header fields. Version is the wire version. ConnectionID must be nonempty exactly when ContentType is ContentTypeConnectionID.
type UnpackDatagramConfig ¶
type UnpackDatagramConfig struct {
// TargetVersion selects record forms; zero permits both DTLS 1.2 and 1.3.
TargetVersion protocol.Version
// CIDLength is the known receive CID length used to locate record fields.
CIDLength int
// CIDRequired requires CID on each protected DTLS 1.2 record, or at least
// once per DTLS 1.3 datagram containing unified records.
CIDRequired bool
// contains filtered or unexported fields
}
UnpackDatagramConfig configures datagram framing.