Skip to main content

Responder

Struct Responder 

Source
pub struct Responder { /* private fields */ }
Expand description

Noise responder state for one connection.

Implementations§

Source§

impl Responder

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn suite(&self) -> Suite

Returns the cipher suite this handshake runs.

Source

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.

Source

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.

Source

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.

Source

pub fn handshake_finished(&self) -> bool

Returns whether both handshake messages have been processed.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.