Expand description
§xenia-wire
PQC-sealed binary wire protocol for remote-control streams.
Pre-alpha. The wire format is not yet frozen and breaking changes
will land between 0.1.x releases. Do not deploy in production.
§What this crate provides
Session— minimal AEAD session state: a current key, an optional previous key with grace period for rekey, per-session randomsource_id+epoch, monotonic nonce counter, and a 64-slot sliding replay window.ReplayWindow— sliding-window replay protection keyed by(source_id, payload_type). IPsec/DTLS semantics.Sealable— generic bincode-based serialization contract. Bring your own payload type.seal/open— generic functions for anySealablepayload.seal_frame/open_frame/seal_input/open_input— convenience wrappers for the referenceFrame+Inputtypes. Available under the defaultreference-framefeature.seal_frame_lz4/open_frame_lz4— LZ4-before-AEAD compression variants. Available under thelz4feature.
§What this crate deliberately does NOT do
- No transport. Sealed bytes are returned to the caller; the caller ships them over TCP / WebSocket / QUIC / whatever.
- No handshake. Session keys arrive from somewhere else
(ML-KEM-768 in real deployments). Call
Session::install_keydirectly in tests or early prototypes. - No state machine.
Sessionhas no lifecycle — no connecting, authenticating, closing. Those are application concerns. - No domain semantics. The reference
Frame/Inputtypes carry opaque byte payloads. ImplementSealableon your own types for anything real.
§Quick start
use xenia_wire::{Session, seal_frame, open_frame, Frame};
let key = [0xAB; 32];
let mut sender = Session::new();
let mut receiver = Session::new();
sender.install_key(key);
receiver.install_key(key);
let frame = Frame {
frame_id: 1,
timestamp_ms: 1_700_000_000_000,
payload: b"hello, xenia".to_vec(),
};
let sealed = seal_frame(&frame, &mut sender).unwrap();
let opened = open_frame(&sealed, &mut receiver).unwrap();
assert_eq!(opened.payload, b"hello, xenia");
// Replaying the same bytes fails — the sliding window catches it.
assert!(open_frame(&sealed, &mut receiver).is_err());§Wire format
envelope = nonce || ciphertext || tag
nonce : 12 bytes — source_id[0..6] || payload_type || epoch || seq[0..4]
ciphertext : len(plaintext) bytes — ChaCha20-Poly1305 encrypt(plaintext)
tag : 16 bytes — Poly1305 authentication tagThe plaintext is typically bincode::serialize(payload). Under the
lz4 feature the plaintext is lz4_flex::compress_prepend_size(bincode_bytes).
§Feature flags
| Feature | Default | Description |
|---|---|---|
reference-frame | yes | Ships Frame + Input reference types. |
lz4 | no | Adds LZ4-before-AEAD variants for frame sealing. |
§License
Dual-licensed under Apache-2.0 OR MIT.
Re-exports§
pub use payload_types::PAYLOAD_TYPE_APPLICATION_MIN;pub use payload_types::PAYLOAD_TYPE_ATTESTED_ACTION;pub use payload_types::PAYLOAD_TYPE_CONSENT_REQUEST;pub use payload_types::PAYLOAD_TYPE_CONSENT_RESPONSE;pub use payload_types::PAYLOAD_TYPE_CONSENT_REVOCATION;pub use payload_types::PAYLOAD_TYPE_FRAME;pub use payload_types::PAYLOAD_TYPE_FRAME_LZ4;pub use payload_types::PAYLOAD_TYPE_INPUT;
Modules§
- consent
consent - Consent ceremony for Xenia sessions (SPEC draft-03 §12).
- payload_
types - Payload-type registry.
Structs§
- Frame
reference-frame - Reference forward-path payload: a primary stream carrying an application-defined byte blob.
- Input
reference-frame - Reference reverse-path payload: an input event batch carrying an application-defined byte blob.
- Replay
Window - Sliding-window replay protection for multiple independent streams.
- Session
- Session state for a single logical stream.
- Session
Builder - Opt-in configuration for a fresh
Session. Constructed viaSession::builder; finalized viaSessionBuilder::build.
Enums§
- Wire
Error - Errors returned by the wire codec.
Constants§
- DEFAULT_
REKEY_ GRACE - Default grace period for the previous session key after a rekey.
- DEFAULT_
WINDOW_ BITS - Default replay window width in bits.
- MAX_
WINDOW_ BITS - Maximum supported replay window width in bits.
- WINDOW_
BITS - Legacy alias for
DEFAULT_WINDOW_BITS. Kept for backwards- compatible public API; new code should useDEFAULT_WINDOW_BITS.
Traits§
- Sealable
- Serialization contract for any payload that can travel over the Xenia wire.
Functions§
- open
- Open a sealed envelope and deserialize it into a
Sealablepayload. - open_
consent_ request consent - Open an envelope sealed by
seal_consent_request. - open_
consent_ response consent - Open an envelope sealed by
seal_consent_response. - open_
consent_ revocation consent - Open an envelope sealed by
seal_consent_revocation. - open_
frame reference-frame - Open a sealed envelope produced by
seal_frame. - open_
frame_ lz4 lz4 - Open a sealed envelope produced by
seal_frame_lz4. - open_
input reference-frame - Open a sealed envelope produced by
seal_input. - seal
- Seal any
Sealablepayload under the session key with the caller-chosen payload type byte. - seal_
consent_ request consent - Seal a
crate::consent::ConsentRequestundercrate::PAYLOAD_TYPE_CONSENT_REQUEST(0x20). - seal_
consent_ response consent - Seal a
crate::consent::ConsentResponseundercrate::PAYLOAD_TYPE_CONSENT_RESPONSE(0x21). - seal_
consent_ revocation consent - Seal a
crate::consent::ConsentRevocationundercrate::PAYLOAD_TYPE_CONSENT_REVOCATION(0x22). - seal_
frame reference-frame - Seal a reference
crate::Frameon the forward path (crate::PAYLOAD_TYPE_FRAME). - seal_
frame_ lz4 lz4 - Seal a reference
crate::Framewith LZ4-before-AEAD compression (crate::PAYLOAD_TYPE_FRAME_LZ4). - seal_
input reference-frame - Seal a reference
crate::Inputon the reverse path (crate::PAYLOAD_TYPE_INPUT).