pub struct Client<R: Read, W: Write> { /* private fields */ }Expand description
Client side of the wire, exchanging encrypted messages over a byte stream.
Client::connect sends a reset and runs the handshake. It returns a
Sender for outbound messages. Client::recv decrypts inbound messages.
An empty frame from the server means it has no session with the client anymore.
The client ends its session and returns Error::SessionReset. The caller
can then reconnect.
Transport checks the shape of the device attestation. A Verifier decides
whether to trust the server presenting it.
Implementations§
Source§impl<R: Read, W: Write> Client<R, W>
impl<R: Read, W: Write> Client<R, W>
Sourcepub fn new(stream: Stream<R, W>) -> Self
pub fn new(stream: Stream<R, W>) -> Self
Creates a client owning the byte stream and its shutdown operation, without
an encrypted session. Call Client::connect to establish one.
Output uses the stream’s configured write timeout; its adapter must
enforce deadlines and the shutdown cancellation contract.
Sourcepub fn set_handshake_timeout(self, timeout: Duration) -> Self
pub fn set_handshake_timeout(self, timeout: Duration) -> Self
Sets the budget for each subsequent handshake, starting when connect is
called. Defaults to DEFAULT_HANDSHAKE_TIMEOUT. Output and peer replies
share one deadline; progress and stale frames do not refresh it. Each
outgoing frame is also limited by the stream’s write timeout. Waiting for
locks and verifier callbacks can extend the call beyond the deadline.
Zero expires attempts immediately. A duration too large to add to an
Instant panics when the next handshake’s deadline is constructed.
Sourcepub fn closer(&self) -> Closer
pub fn closer(&self) -> Closer
A handle that permanently closes the stream from another thread.
Sourcepub fn close(&self)
pub fn close(&self)
Permanently closes the stream and waits for adapter shutdown. Senders
observe closure through write failure; buffered messages remain readable.
See Closer::close.
Sourcepub fn connect<V: Verifier>(
&mut self,
verifier: &V,
) -> Result<(Sender<W>, V::Info), Error>
pub fn connect<V: Verifier>( &mut self, verifier: &V, ) -> Result<(Sender<W>, V::Info), Error>
Establishes an encrypted session over the supplied stream, ending any previous session first. Sends a reset and drives the handshake:
- Client -> Server: HostHello { host_signer, host_crypto } (plain CBOR)
- Server -> Client: ArkHello { ark_attest, ark_crypto, a2h_encap } (cose::seal)
- Client -> Server: HostAck { h2a_encap } (cose::seal)
The verifier receives the server’s device attestation. Its accepted info is returned alongside the new sender. That sender belongs to this session and cannot send into a replacement established by a later handshake.
Sends reset and hello before draining old input. The adapter must allow that output to finish without concurrent client reads for this attempt to progress. Backpressure can instead fail an outgoing frame on timeout.
The handshake uses one configured deadline, shared by output and peer waits. Existing writer-lock cleanup may extend the call. If connecting fails, the client has no session and previously issued senders are invalid.
Sourcepub fn recv(&mut self) -> Result<Vec<u8>, Error>
pub fn recv(&mut self) -> Result<Vec<u8>, Error>
Reads and decrypts the next ark-to-host message. Invalid or oversized
frames end the session because its encryption sequence may be lost.
Decryption failures also end the session.
An empty frame means the server dropped the session and ends it here too.
Adapter read failures and EOF also end the session. Idle read timeouts are
retried internally. Call Self::connect to establish a new session after failure.
Without a receive context, returns an error without reading the stream.
After decryption, message acceptance is ordered with session ending without waiting for the writer. A concurrent send failure can cause a decrypted message to be discarded before acceptance. An accepted message may reach this caller after another thread ends the session. Returning a receive error does wait for outgoing writes to finish.