enigma-packet 0.1.0

Canonical message packet format + serialization for Enigma secure messaging
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
# Validation Rules

The `validate_message` function enforces deterministic, fail-fast constraints before any message is encoded and after every decode.

1. **Participants**: `sender` and `receiver` must be UTF-8 strings between 1 and 64 Unicode scalar values (inclusive).
2. **Timestamp**: `timestamp_ms` must be greater than zero for every packet.
3. **Text and Inline Media**: Text payloads must be valid UTF-8. Voice/Image/Video/File/Call* messages may include arbitrary bytes but may only use `MessageMeta::Basic` (or `MessageMeta::None`). No maximum payload length is enforced beyond the frame safety bound.
4. **AttachmentInit**: Payload must be empty. `AttachmentMeta` needs positive `total_size`, `chunk_size`, and `chunk_count`. `chunk_count` must equal `ceil(total_size / chunk_size)`. File attachments must provide a non-empty filename.
5. **AttachmentChunk**: Payload must be non-empty and no larger than the declared `chunk_size`. `offset` must equal `index * chunk_size`. If `total_size` is supplied it must be positive and `offset + payload.len()` cannot exceed it.
6. **AttachmentEnd**: Payload must be empty while `total_size` and `chunk_count` remain positive. Optional SHA-256 values are fixed to 32 bytes by type.
7. **AttachmentAbort/Ack**: Payloads must be empty and metadata must include the target `attachment_id` (additional fields such as reason or received index are optional).

Violations raise `EnigmaPacketError::ValidationError`, ensuring no malformed data reaches the codec or dependent systems. Applications remain responsible for deciding how large an attachment they are willing to send or accept.