1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! # Phantom Protocol SDK
//!
//! Post-quantum secure L4/L6 universal transport framework.
//!
//! Provides:
//! - Hybrid key exchange (X25519 + ML-KEM-768; X-Wing-style combiner). Under
//! `--features fips` the classical half swaps to ECDH-P-256.
//! - Hybrid signatures (Ed25519 + ML-DSA-65) — both halves must verify.
//! - PhantomUDP, a native reliable transport over raw UDP (the production
//! transport), plus byte-pipe `SessionTransport` impls for TCP, browser
//! WebSocket, WASI, embedded UART/USB, and an off-by-default TLS-mimicry leg.
//! - Seamless single-path connection migration (not multipath aggregation —
//! that was deliberately rejected) with liveness detection and keep-alive PINGs.
//! - Stream multiplexing (reliable + unreliable).
//!
//! The core transmits only `Vec<u8>` / `Bytes`.
//! Serialization (JSON, Protobuf, etc.) is the user's responsibility.
// Security-friendly lints. Now `deny` (was `warn` until the codebase drove the
// remaining unannotated sites to zero). Every surviving panic-shaped call in
// production code carries an inline `// PANIC-SAFETY:` comment and a narrow
// `#[allow(clippy::unwrap_used)]` / `#[allow(clippy::expect_used)]` at the
// statement scope; the canonical inventory lives in `docs/security/panic-sites.md`.
// Tests opt in to `expect_used` for readable failure diagnostics. Phase 1.3
// (Production Readiness) — closed.
//
// `clippy::indexing_slicing` is deliberately omitted at this stage — it fires
// on every constant-bounded array index and would generate too much noise.
// It is tracked as a separate phase 1.13 item (bounds-check audit).
//
// On docs.rs — which sets `--cfg docsrs` on nightly via the
// `[package.metadata.docs.rs]` table — auto-generate "Available on crate
// feature X" badges for every `#[cfg(feature = …)]`-gated item. `doc_auto_cfg`
// was merged into `doc_cfg` in Rust 1.92, which now carries the auto-cfg
// behaviour. The attribute is inert on every normal (stable) build: `docsrs` is
// never set there, so the unstable `doc_cfg` feature is never requested.
// Tests use `expect()` / `unwrap()` / `panic!()` freely so failures surface as
// readable diagnostics rather than swallowed `Result`s. The `deny` above only
// governs the production code path; this `cfg_attr(test, allow(...))` flips
// the same lints back to permissive for `cargo test` builds.
// Deny `unsafe` by default at the crate root. The three modules that genuinely
// require `unsafe` (a single `libc::setsockopt(SO_MAX_PACING_RATE)` call in
// `transport::udp_transport`, native-only — the dead `sendmmsg` GSO path was
// removed; wasm-bindgen-generated JS-boundary glue in
// `transport::legs::websocket`, wasm32-only; `unsafe impl Send/Sync for
// WasiLeg` over WIT-bindgen `Resource<T>` socket handles in
// `transport::legs::wasi`, WASI-only) opt back in with a module-level
// `#![allow(unsafe_code)]` and per-block `// SAFETY:` comments. Audit lens:
// any future PR touching `unsafe` outside those three modules will fail this
// lint and must justify itself explicitly.
// Phase 3.6: when neither `std` nor any std-implying feature is on, drop std
// from the crate root so a bare-metal `--no-default-features --features
// embedded,no-std` build links only `core` + `alloc`. The std build (the
// default) is unchanged.
// Phase 5.5 / A8 — the FIPS 140-3 primitive swap (X25519 → ECDH-P-256,
// ring → aws-lc-rs, blake3 → HKDF-SHA256, drop ChaCha20-Poly1305,
// CTR_DRBG RNG, POST hook) is **shipped**. `--features fips` now
// builds and serves a FIPS-substrate Phantom Protocol. The scaffold
// `compile_error!` from commit `d4d121b` is gone; the only
// remaining build-time gate enforces mutual exclusion with `no-std`,
// since `aws-lc-rs` requires libc + dlopen / OpenSSL ABI and cannot
// run on bare-metal.
compile_error!;
// B1 — the `wasi-leg` Cargo feature lives at the WASI target (the
// `wasi` crate's WIT bindings are only available there). Enabling it
// on `wasm32-unknown-unknown` (the browser target with WebSocketLeg /
// WasmRuntime) is a misconfiguration; fail the build loudly with a
// pointer at the recipe.
compile_error!;
extern crate alloc;
// `errors` and the `transport::session_transport` / `transport::legs::embedded`
// subtree are no_std-clean and compile under both feature configurations.
// ── std-only top-level modules ─────────────────────────────────────────
// The bare-metal subset (Phase 3.6) compiles only `errors` and the embedded
// transport subset. Everything below is gated behind `std`: it either uses
// `tokio`, `parking_lot`, `dashmap`, raw sockets, `std::time::Instant`,
// `std::sync::*`, or a std-bound dep (e.g. `ml-kem`, the classical-crypto
// `ring` / `x25519-dalek`) that is itself only compiled when `std` is on.
// Crypto module (hybrid KEM, hybrid sign) — std-only: pulls `ed25519-dalek`,
// `ml-kem`, `ml-dsa` unconditionally, plus `ring` + `x25519-dalek` via the
// default-on `classical-crypto` feature. Under `--features fips` the classical
// substrate swaps to `aws-lc-rs` (`ring` / `x25519-dalek` dropped entirely).
// Transport module (Phantom Protocol transport). The module itself has a
// no_std-clean subset (`session_transport`, `legs::embedded`). The rest of the
// sub-modules opt into `std` from within `transport/mod.rs`.
// Async runtime abstraction (Phase 3.1). `TokioRuntime` is the default
// implementation; `WasmRuntime` (browser), `EmbeddedRuntime` (host-thread
// scaffold), and `WasiRuntime` (WASI Preview 2) are the shipped alternate
// backends, injected via the `_with_runtime` API variants.
// Public API facade — std-only: every entry point (`PhantomSession`,
// `PhantomListener`, `TcpSessionTransport`) depends on `tokio`.
// Test harness for network simulation
// Public exports
pub use PhantomConfig;
pub use CoreError;
// UniFFI scaffolding. Gated on the `bindings` feature so the WASI
// guest build (which sets `--features wasi-leg` without `bindings`)
// skips it — UniFFI's exported-symbol metadata is incompatible with
// `wasm-component-ld`, the wasm32-wasip2 linker. Default builds keep
// `bindings` active, so the native FFI consumers (Swift / Kotlin /
// Python / C bindings) see the historical surface unchanged.
setup_scaffolding!;