MatterEx.Protocol.MessageCodec (matter_ex v0.3.0)

Copy Markdown View Source

Matter message frame encode/decode.

Handles the full message wire format: plaintext message header (AAD) followed by protocol header + payload (encrypted for active sessions) and a 16-byte MIC tag.

Summary

Functions

Build a 13-byte AES-CCM nonce per Matter spec.

Decode a plaintext message frame.

Decode an encrypted message frame. The plaintext header is decoded first, then the remaining ciphertext (minus the 16-byte MIC) is decrypted.

Encode a plaintext message (used during PASE setup, session_id = 0).

Encode an encrypted message. The message header becomes AAD, the protocol header + payload are encrypted, and the 16-byte MIC is appended.

Types

Functions

build_nonce(security_flags, message_counter, source_node_id \\ 0)

@spec build_nonce(byte(), non_neg_integer(), non_neg_integer()) :: binary()

Build a 13-byte AES-CCM nonce per Matter spec.

<<security_flags::8, message_counter::little-32, source_node_id::little-64>>

decode(binary)

@spec decode(binary()) :: {:ok, message()} | {:error, atom()}

Decode a plaintext message frame.

decode_encrypted(binary, key, nonce)

@spec decode_encrypted(binary(), binary(), binary()) ::
  {:ok, message()} | {:error, atom()}

Decode an encrypted message frame. The plaintext header is decoded first, then the remaining ciphertext (minus the 16-byte MIC) is decrypted.

encode(header, proto)

Encode a plaintext message (used during PASE setup, session_id = 0).

encode_encrypted(header, proto, key, nonce)

Encode an encrypted message. The message header becomes AAD, the protocol header + payload are encrypted, and the 16-byte MIC is appended.