Skip to main content

Initiator

Struct Initiator 

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

Noise initiator state for one connection: the server half.

The server always sends the first handshake message, so this type produces message 1 and consumes message 2. It starts with the published Sentinel PSK; Initiator::set_psk selects the key the session will actually use, which message 1 must announce.

The suite is the one the client announced in client/init: a server must run exactly that one, because the client builds its responder for it. There is no fallback - Initiator::new refuses a prologue that announces another suite, and Initiator::with_announced_suite takes the suite from the announcement so the two cannot disagree.

Implementations§

Source§

impl Initiator

Source

pub fn new( identity: &Identity, peer_public: &[u8; 32], suite: Suite, prologue: &[u8], ) -> Result<Initiator>

Builds the initiator for an explicit peer key and suite.

prologue reaches Noise unchanged, so both sides must mix in the same bytes: the exact client/init and server/init of a first handshake, or the previous handshake hash on a re-handshake. When the prologue carries a client/init, the suite it announces must be suite; a prologue that carries no announcement - a re-handshake hash, which is not JSON - leaves suite as the only source, and a suite this build does not have is always refused.

Source

pub fn with_announced_suite( identity: &Identity, peer_public: &[u8; 32], prologue: &[u8], ) -> Result<Initiator>

Builds the initiator for the suite the prologue’s client/init announces.

This is the constructor for a first handshake: the announcement decides the suite, so the two cannot disagree. A prologue that is not the init exchange, that carries no client/init, that carries two of them, that announces no suite or that announces one this build does not have is rejected; use Initiator::new on a re-handshake, where the prologue is the previous handshake hash.

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 initiator starts with the published Sentinel PSK. Call this before writing message 1 when the handshake announces a private key, because message 1’s payload names the key this call selects; noise mixes the key into message 2 either way, so both sides must use the same value or the peer’s message 2 does not authenticate.

Source

pub fn write_message(&mut self, payload: &[u8]) -> Result<Vec<u8>>

Writes Noise handshake message 1 with payload and returns the message.

The payload is the PSK metadata (psk_id, psk_category) the session layer builds; this module does not interpret it. It travels encrypted, so it must fit into a Noise message.

Source

pub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>>

Reads Noise handshake message 2 and returns its decrypted payload.

The payload is returned verbatim; Sendspin requires it to be the empty JSON object, which the session layer checks. Fails when the message does not authenticate, which covers a message sealed with another PSK, a changed byte and a truncation.

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.

Returns what Responder::into_transport returns: the handshake hash a re-handshake mixes in and the suite these keys were derived under. Fails if message 2 is still outstanding, which Initiator::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.