Struct snow::HandshakeState

source ·
pub struct HandshakeState { /* private fields */ }
Expand description

A state machine encompassing the handshake phase of a Noise session.

Note: you are probably looking for Builder to get started.

See: https://noiseprotocol.org/noise.html#the-handshakestate-object

Implementations§

source§

impl HandshakeState

source

pub fn was_write_payload_encrypted(&self) -> bool

This method will return true if the previous write payload was encrypted.

See Payload Security Properties for more information on the specific properties of your chosen handshake pattern.

§Examples
let mut session = Builder::new("Noise_NN_25519_AESGCM_SHA256".parse()?)
    .build_initiator()?;

// write message...

assert!(session.was_write_payload_encrypted());
source

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

Construct a message from payload (and pending handshake tokens if in handshake state), and writes it to the message buffer.

Returns the size of the written payload.

§Errors

Will result in Error::Input if the size of the output exceeds the max message length in the Noise Protocol (65535 bytes).

source

pub fn read_message( &mut self, message: &[u8], payload: &mut [u8] ) -> Result<usize, Error>

Reads a noise message from input

Returns the size of the payload written to payload.

§Errors

Will result in Error::Decrypt if the contents couldn’t be decrypted and/or the authentication tag didn’t verify.

Will result in StateProblem::Exhausted if the max nonce count overflows.

source

pub fn set_psk(&mut self, location: usize, key: &[u8]) -> Result<(), Error>

Set the preshared key at the specified location. It is up to the caller to correctly set the location based on the specified handshake - Snow won’t stop you from placing a PSK in an unused slot.

§Errors

Will result in Error::Input if the PSK is not the right length or the location is out of bounds.

source

pub fn get_remote_static(&self) -> Option<&[u8]>

Get the remote party’s static public key, if available.

Note: will return None if either the chosen Noise pattern doesn’t necessitate a remote static key, or if the remote static key is not yet known (as can be the case in the XX pattern, for example).

source

pub fn get_handshake_hash(&self) -> &[u8]

Get the handshake hash.

Returns a slice of length Hasher.hash_len() (i.e. HASHLEN for the chosen Hash function).

source

pub fn is_initiator(&self) -> bool

Check if this session was started with the “initiator” role.

source

pub fn is_handshake_finished(&self) -> bool

Check if the handshake is finished and into_transport_mode() can now be called.

source

pub fn is_my_turn(&self) -> bool

Check whether it is our turn to send in the handshake state machine

source

pub fn into_transport_mode(self) -> Result<TransportState, Error>

Convert this HandshakeState into a TransportState with an internally stored nonce.

source

pub fn into_stateless_transport_mode( self ) -> Result<StatelessTransportState, Error>

Convert this HandshakeState into a StatelessTransportState without an internally stored nonce.

Trait Implementations§

source§

impl Debug for HandshakeState

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TryFrom<HandshakeState> for StatelessTransportState

§

type Error = Error

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

fn try_from(old: HandshakeState) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<HandshakeState> for TransportState

§

type Error = Error

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

fn try_from(old: HandshakeState) -> Result<Self, Self::Error>

Performs the conversion.

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

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.