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.

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.

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.

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.

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.