Struct snow::TransportState

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

A state machine encompassing the transport phase of a Noise session, using the two CipherStates (for sending and receiving) that were spawned from the SymmetricState’s Split() method, called after a handshake has been finished.

Also see: the relevant Noise spec section.

Implementations§

source§

impl TransportState

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 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 output 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, payload: &[u8], message: &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 overflows.

source

pub fn rekey_outgoing(&mut self)

Generates a new key for the egress symmetric cipher according to Section 4.2 of the Noise Specification. Synchronizing timing of rekey between initiator and responder is the responsibility of the application, as described in Section 11.3 of the Noise Specification.

source

pub fn rekey_incoming(&mut self)

Generates a new key for the ingress symmetric cipher according to Section 4.2 of the Noise Specification. Synchronizing timing of rekey between initiator and responder is the responsibility of the application, as described in Section 11.3 of the Noise Specification.

source

pub fn rekey_manually( &mut self, initiator: Option<&[u8]>, responder: Option<&[u8]> )

Set a new key for the one or both of the initiator-egress and responder-egress symmetric ciphers.

source

pub fn rekey_initiator_manually(&mut self, key: &[u8])

Set a new key for the initiator-egress symmetric cipher.

source

pub fn rekey_responder_manually(&mut self, key: &[u8])

Set a new key for the responder-egress symmetric cipher.

source

pub fn set_receiving_nonce(&mut self, nonce: u64)

Sets the receiving CipherState’s nonce. Useful for using noise on lossy transports.

source

pub fn receiving_nonce(&self) -> u64

Get the forthcoming inbound nonce value.

§Errors

Will result in Error::State if not in transport mode.

source

pub fn sending_nonce(&self) -> u64

Get the forthcoming outbound nonce value.

§Errors

Will result in Error::State if not in transport mode.

source

pub fn is_initiator(&self) -> bool

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

Trait Implementations§

source§

impl Debug for TransportState

source§

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

Formats the value using the given formatter. Read more
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.