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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// wire-rs: encrypted protocol between Ark and host
// Copyright 2026 Dark Bio AG. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//! Encrypted sessions over a duplex byte stream.
//!
//! COBS framing separates packets, the handshake establishes encryption
//! contexts, and sealing protects messages. Each [`Client`] or [`Server`] owns
//! its receive context and shares its send context with active sends.
//! [`Sender`] handles allow other threads to send into that session.
//!
//! Adapters implement standard byte I/O plus the deadline setters in [`Read`]
//! and [`Write`]. Each outgoing frame has one configurable budget covering
//! partial writes and flush. A timeout ends that send or handshake without
//! closing the byte stream. Established-session reads wait for data or adapter
//! shutdown, with no session timeout. Handshakes use one configurable deadline
//! on each side, defaulting to 5 s.
//!
//! The client writes reset and hello before draining stale replies, so adapters
//! need enough available buffering to accept that output without concurrent
//! client reads. Backpressure may fail an attempt; the caller can retry with a
//! fresh reset.
use Duration;
pub use ;
pub use ;
pub use Sender;
pub use ;
pub use ;
/// Default budget of 5 s for a handshake's output and peer replies.
///
/// Configure it with [`Client::set_handshake_timeout`] or
/// [`Server::set_handshake_timeout`]. Progress, stale frames and resets within
/// the attempt do not refresh it. Waiting for the writer lock and for caller
/// callbacks may extend the call, but cannot extend its I/O deadline.
pub const DEFAULT_HANDSHAKE_TIMEOUT: Duration = from_secs;
/// Default budget of 5 s for encoding, writing and flushing one complete
/// transport frame.
///
/// Configure it with [`Stream::set_write_timeout`]. Progress does not refresh
/// it. The budget starts after acquiring the writer, excluding lock waits and
/// encryption. Handshake frames are also limited by the handshake deadline.
pub const DEFAULT_WRITE_TIMEOUT: Duration = from_secs;
/// Maximum encoded frame size of 2 MiB, excluding its trailing delimiter.
///
/// An oversized incoming frame is a framing error that ends any active session.
/// Its remainder is discarded through its delimiter so the stream can carry a
/// fresh handshake.
pub const MAX_FRAME_SIZE: usize = 2 * 1024 * 1024;
/// Conservative soft limit for outgoing message sizes, guaranteed to fit a
/// frame after sealing and worst-case COBS overhead.
///
/// The wire's hard limit is [`MAX_FRAME_SIZE`]; received messages may exceed
/// this value if their encoded frames fit. Sending uses this conservative bound
/// to reject oversized messages before sealing, without advancing the
/// encryption sequence.
pub const MAX_MESSAGE_SIZE: usize = ;
/// Domain separator for the handshake's COSE envelopes,
/// [`ArkHello`](handshake::ArkHello) and [`HostAck`](handshake::HostAck).
///
/// [`HostHello`](handshake::HostHello) is plain CBOR. The separator binds
/// signatures and encryption to this protocol, preventing their reuse in
/// another protocol with the same key.
pub const CRYPTO_DOMAIN_WIRE: & = b"wire-v1";
/// HPKE info string for the ark-to-host encryption context of an established
/// session (message traffic after the handshake, not the handshake itself).
pub const CRYPTO_DOMAIN_WIRE_ARK_TO_HOST: & = b"wire-v1:ark-to-host";
/// HPKE info string for the host-to-ark encryption context of an established
/// session (message traffic after the handshake, not the handshake itself).
pub const CRYPTO_DOMAIN_WIRE_HOST_TO_ARK: & = b"wire-v1:host-to-ark";
/// Things that can go wrong in the wire transport.