Zer0 Secret Stream
Framing
Frame format in `zer0-secret-stream` — length-prefixed records with per-frame authentication and constant-time decode.
Purpose
Noise-style secret stream with handshakes, framing, bridge IO, tunables, metrics, and typed errors.
This page follows the real source shape for Zer0 Secret Stream and explains the workflow a developer is likely to use first.
Developer workflow
Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.
Primary types to know
Bridge— network/zer0-secret-stream/src/bridge.rsBridgeReverse— network/zer0-secret-stream/src/bridge.rsHandshake— network/zer0-secret-stream/src/handshake.rsHandshakeResult— network/zer0-secret-stream/src/handshake.rsMessage— network/zer0-secret-stream/src/lib.rsSecretOptions— network/zer0-secret-stream/src/lib.rsSecretStream— network/zer0-secret-stream/src/lib.rsSecretStreamMetrics— network/zer0-secret-stream/src/metrics.rsSecretStreamMetricsSnapshot— network/zer0-secret-stream/src/metrics.rsSecretTunables— network/zer0-secret-stream/src/config.rsHandshakeError— network/zer0-secret-stream/src/handshake.rsHandshakePattern— network/zer0-secret-stream/src/handshake.rs
Example shape
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use zer0_secret_stream::{Message, SecretOptions, SecretStream};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// The framing layer prefixes every Message with its length and per-frame
// nonce. Reads block until a full frame arrives, so partial network reads
// are buffered transparently.
let (alice_inner, bob_inner) = tokio::io::duplex(64 * 1024);
let mut alice = SecretStream::new(alice_inner, true, SecretOptions::default())?;
let mut bob = SecretStream::new(bob_inner, false, SecretOptions::default())?;
let outbound = Message::data(b"hello, bob".to_vec());
alice.send(outbound).await?;
let mut buf = [0u8; 1024];
let n = bob.read(&mut buf).await?;
println!("bob_received_bytes={} alice_state={:?}", n, alice.state());
Ok(())
}