pub struct Responder { /* private fields */ }Expand description
Noise responder state for one connection.
Implementations§
Source§impl Responder
impl Responder
Sourcepub fn new(identity: &Identity, prologue: &[u8]) -> Result<Responder>
pub fn new(identity: &Identity, prologue: &[u8]) -> Result<Responder>
Builds the responder for the client side of a Sendspin handshake, using the suite the
prologue’s client/init announces.
prologue must be the exact concatenation of the client/init and server/init bytes
as transmitted, in that order. It is mixed into the handshake verbatim, the initiator’s
static public key is read from the server_id field of the server/init document it
contains, and the cipher suite from the suite field of client/init. A prologue that
is not a sequence of JSON documents, that carries no server/init, that carries two of
them, that announces no suite or that announces one this build does not have is
rejected; use Responder::with_peer when the key is already known, as during a
re-handshake where the prologue is the previous handshake hash.
Sourcepub fn with_suite(
identity: &Identity,
suite: Suite,
prologue: &[u8],
) -> Result<Responder>
pub fn with_suite( identity: &Identity, suite: Suite, prologue: &[u8], ) -> Result<Responder>
Builds the responder for the suite the prologue announces, refusing any other.
This is Responder::new with an explicit choice, for a caller that must pin the suite.
A prologue whose client/init announces a different suite is an error: honouring the
caller’s suite would hand the peer a handshake it cannot follow, and switching to the
announced one would be a silent downgrade of what the caller asked for.
Sourcepub fn with_peer(
identity: &Identity,
peer_public: &[u8; 32],
prologue: &[u8],
) -> Result<Responder>
pub fn with_peer( identity: &Identity, peer_public: &[u8; 32], prologue: &[u8], ) -> Result<Responder>
Builds the responder with the initiator’s static public key supplied explicitly, for the
default suite Suite::ChaChaPoly.
Use this when the prologue is not the init exchange, for example on a re-handshake whose
prologue is the previous handshake hash. prologue still reaches Noise unchanged; both
sides must mix in the same bytes. A re-handshake must keep the suite of the connection it
replaces, so a caller that can offer more than one suite must use
Responder::with_peer_suite and pass the suite the connection already runs.
Sourcepub fn with_peer_suite(
identity: &Identity,
peer_public: &[u8; 32],
suite: Suite,
prologue: &[u8],
) -> Result<Responder>
pub fn with_peer_suite( identity: &Identity, peer_public: &[u8; 32], suite: Suite, prologue: &[u8], ) -> Result<Responder>
Builds the responder for an explicit peer key and suite.
This is the constructor every other one ends in. It does not read the prologue, so it is the one to use on a re-handshake, where the prologue is the previous handshake hash and carries no announcement.
Sourcepub fn set_psk(&mut self, psk: &[u8; 32]) -> Result<()>
pub fn set_psk(&mut self, psk: &[u8; 32]) -> Result<()>
Replaces the pre-shared key used by the rest of the handshake.
The responder starts with the published Sentinel PSK because the key is selected from the
metadata that message 1 carries. Call this after Responder::read_message and before
Responder::write_message: Noise mixes the key into message 2, so both sides must use
the same value and the initiator rejects a message sealed with another one.
§Errors
The call is forwarded to snow, which refuses only a key of the wrong length or an
out-of-range location; both are fixed here, so this does not fail in practice. snow does
not refuse a late call either: the key must be set before Responder::write_message
seals message 2, and a later call has no effect on the handshake or on the message already
sealed.
Sourcepub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>>
pub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>>
Reads one Noise handshake message and returns its decrypted payload.
The payload is returned verbatim. Message 1 carries the PSK metadata
(psk_id, psk_category) for the session layer to validate; the handshake itself starts
with the Sentinel PSK, which Responder::set_psk can replace.
Sourcepub fn write_message(&mut self) -> Result<Vec<u8>>
pub fn write_message(&mut self) -> Result<Vec<u8>>
Writes Noise handshake message 2 and returns it.
The payload is the empty JSON object that Sendspin requires; it is not configurable.
Sourcepub fn handshake_finished(&self) -> bool
pub fn handshake_finished(&self) -> bool
Returns whether both handshake messages have been processed.
Sourcepub fn into_transport(self) -> Result<TransportState>
pub fn into_transport(self) -> Result<TransportState>
Finishes the handshake and switches to transport mode.
Fails if a handshake message is still outstanding, which
Responder::handshake_finished reports ahead of time.