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.
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, and the
initiator’s static public key is read from the server_id field of the server/init
document it contains. A prologue that is not a sequence of JSON documents, that carries
no server/init, or that carries two of them 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_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.
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.
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
Fails when the handshake has already mixed in the key, which makes a late change impossible.
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.