Skip to main content

Module msg

Module msg 

Source
Expand description

The Matter message frame: headers, identifiers, and the counters that keep a message from being replayed.

This is Core §4.4–4.9 — everything between “some bytes arrived on a socket” and “this is a protocol message for exchange 7”. What is here is the framing and the anti-replay machinery; encryption arrives with the secure channel, and the layout below is already shaped for it (the header is outside the ciphertext because a receiver must find the key before it can decrypt).

┌── message header ─────────────────────────┐┌── payload (encrypted) ──┐┌ footer ┐
│ flags │ session │ sec │ counter │ src │ dst││ protocol header │ app   ││  MIC   │
└───────────────────────────────────────────┘└─────────────────────────┘└────────┘
use matter_kit::msg::{Destination, MessageHeader, NodeId, SessionId};

let header = MessageHeader {
    session_id: SessionId(0x1234),
    message_counter: 42,
    source: Some(NodeId(1)),
    destination: Destination::Node(NodeId(2)),
    ..MessageHeader::default()
};

let mut buf = [0u8; 64];
let n = header.encode(&mut buf)?;
let (decoded, payload) = MessageHeader::decode(&buf[..n])?;
assert_eq!(decoded, header);
assert!(payload.is_empty());

Structs§

CaseAuthenticatedTag
A CASE Authenticated Tag: an access-control subject shared by a group of nodes (Core §6.6.2.1.2).
CounterWindow
The message reception state for one peer or session (§4.6.5.1).
ExchangeFlags
The Exchange Flags octet (§4.4.3.1).
ExchangeId
A 16-bit exchange identifier (Core §4.4.3.3).
FabricId
A 64-bit Fabric ID (Core §2.5.1).
FabricIndex
A local index into a node’s own fabric table (Core §7.5).
GroupId
A 16-bit Group ID (Core §2.5.4).
MessageCounter
The initial value is random (§4.6.1.1), which is why MessageCounter::new takes one rather than starting at zero: a counter that always starts at 1 leaks how many times a device has rebooted, and makes nonce reuse across a factory reset far too easy.
MessageFlags
The Message Flags octet (§4.4.1.1).
MessageHeader
The unencrypted header every Matter message starts with (§4.4.1).
NodeId
A 64-bit Node ID (Core §2.5.5).
Previewrustcrypto
What a receiver can read before it has found a key.
ProtocolHeader
The header at the start of a message’s payload (§4.4.3).
ProtocolId
A protocol identifier, which is a Vendor ID and a 16-bit protocol number (Core §4.4.3.5).
SecurityFlags
The Security Flags octet (§4.4.1.3).
SessionId
A 16-bit session identifier (Core §4.4.1.2).
SessionKeysrustcrypto
The keys one session protects its messages with.
VendorId
A 16-bit Vendor ID (Core §2.5.2).

Enums§

CounterKind
Which duplicate-detection rule applies to a counter space (§4.6.5.2).
Destination
The Destination Node ID field, whose size and meaning the DSIZ field sets (§4.4.1.1, §4.4.1.6).
NodeIdKind
What range of the Node ID space a value falls in (Core §2.5.5).
NonceSourcerustcrypto
Where the Source Node ID in the AEAD nonce comes from (§4.8.1.1).
SessionType
The kind of session a message belongs to (§4.4.1.3).
Verdict
What a receiver should do with an arriving counter.

Constants§

MESSAGE_FORMAT_VERSION
The Matter message format version this crate speaks (§4.4.1.1).
MSG_COUNTER_WINDOW_SIZE
“Maximum number of previously processed messages” a receiver remembers per peer (Core Table 20).

Functions§

initial_counter
A sender’s own counter for one key (§4.6.1).
previewrustcrypto
Reads the four octets of a message that are always in the clear.
protectrustcrypto
Encrypts one message into out, returning how many octets it occupies.
unprotectrustcrypto
Decrypts one message in place, returning its header and the range of buf holding the plaintext payload.