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§
- Case
Authenticated Tag - A CASE Authenticated Tag: an access-control subject shared by a group of nodes (Core §6.6.2.1.2).
- Counter
Window - The message reception state for one peer or session (§4.6.5.1).
- Exchange
Flags - The Exchange Flags octet (§4.4.3.1).
- Exchange
Id - A 16-bit exchange identifier (Core §4.4.3.3).
- Fabric
Id - A 64-bit Fabric ID (Core §2.5.1).
- Fabric
Index - A local index into a node’s own fabric table (Core §7.5).
- GroupId
- A 16-bit Group ID (Core §2.5.4).
- Message
Counter - The initial value is random (§4.6.1.1), which is why
MessageCounter::newtakes 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. - Message
Flags - The Message Flags octet (§4.4.1.1).
- Message
Header - The unencrypted header every Matter message starts with (§4.4.1).
- NodeId
- A 64-bit Node ID (Core §2.5.5).
- Preview
rustcrypto - What a receiver can read before it has found a key.
- Protocol
Header - The header at the start of a message’s payload (§4.4.3).
- Protocol
Id - A protocol identifier, which is a Vendor ID and a 16-bit protocol number (Core §4.4.3.5).
- Security
Flags - The Security Flags octet (§4.4.1.3).
- Session
Id - A 16-bit session identifier (Core §4.4.1.2).
- Session
Keys rustcrypto - The keys one session protects its messages with.
- Vendor
Id - A 16-bit Vendor ID (Core §2.5.2).
Enums§
- Counter
Kind - Which duplicate-detection rule applies to a counter space (§4.6.5.2).
- Destination
- The Destination Node ID field, whose size and meaning the
DSIZfield sets (§4.4.1.1, §4.4.1.6). - Node
IdKind - What range of the Node ID space a value falls in (Core §2.5.5).
- Nonce
Source rustcrypto - Where the Source Node ID in the AEAD nonce comes from (§4.8.1.1).
- Session
Type - 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).
- preview
rustcrypto - Reads the four octets of a message that are always in the clear.
- protect
rustcrypto - Encrypts one message into
out, returning how many octets it occupies. - unprotect
rustcrypto - Decrypts one message in place, returning its header and the range of
bufholding the plaintext payload.