Skip to main content

darkbio_wire/
lib.rs

1// wire-rs: encrypted protocol between Ark and host
2// Copyright 2025 Dark Bio AG. All rights reserved.
3
4// Allow excluding test code from coverage measurements on nightly
5#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
6// Pull in the README as the package doc
7#![doc = include_str!("../README.md")]
8
9pub mod memory;
10pub mod protocol;
11pub mod transport;
12
13#[cfg(any(test, feature = "fuzz"))]
14#[doc(hidden)]
15pub use transport::mock;
16
17pub use protocol::{ArkToHost, HostToArk};
18pub use transport::{
19    Attestation, Attester, Client, Closer, DEFAULT_HANDSHAKE_TIMEOUT, DEFAULT_WRITE_TIMEOUT, Error,
20    MAX_FRAME_SIZE, MAX_MESSAGE_SIZE, Read, Roots, Sender, Server, Stream, Verifier, Write,
21};
22
23use std::fmt;
24use std::sync::atomic::{AtomicU64, Ordering};
25
26/// Labels a session or a message in log lines and nothing else. Sessions get
27/// a process-local number the peer never sees. The type derives no equality
28/// or hashing and exposes no number, so nothing can route or match on it.
29#[derive(Clone, Copy, Debug, Default)]
30pub(crate) struct LogId(u64);
31
32impl From<u64> for LogId {
33    fn from(id: u64) -> Self {
34        Self(id)
35    }
36}
37
38impl fmt::Display for LogId {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        self.0.fmt(f)
41    }
42}
43
44/// Numbers the sessions of every client and server in the process, so log
45/// lines can be followed from a session's establishment to its end.
46static SESSIONS: AtomicU64 = AtomicU64::new(0);
47
48/// Allocates the next session label, starting from one.
49pub(crate) fn next_log_id() -> LogId {
50    LogId(SESSIONS.fetch_add(1, Ordering::Relaxed) + 1)
51}
52
53#[cfg(test)]
54#[cfg_attr(coverage_nightly, coverage(off))]
55mod testing;