State

Enum State 

Source
pub enum State {
    NotInitialized(usize),
    HandShake(HandshakeRole),
    Transport(NoiseCodec),
}
Expand description

Represents the state of the Noise protocol codec during different phases: initialization, handshake, or transport mode, where encryption and decryption are fully operational.

The state transitions from initialization State::NotInitialized to handshake State::HandShake and finally to transport mode State::Transport as the encryption handshake is completed.

Variants§

§

NotInitialized(usize)

The codec has not been initialized yet.

This state is used when the codec is first created or reset, before the handshake process begins. The variant carries the expected size of the handshake message, which can vary depending on whether the codec is acting as an initiator or a responder.

§

HandShake(HandshakeRole)

The codec is in the handshake phase, where cryptographic keys are being negotiated.

In this state, the codec is in the process of establishing secure communication by exchanging handshake messages. Once the handshake is complete, the codec transitions to State::Transport mode.

§

Transport(NoiseCodec)

The codec is in transport mode, where AEAD encryption and decryption are fully operational.

In this state, the codec is performing full encryption and decryption using the Noise protocol in transport mode. The NoiseCodec object is responsible for handling the encryption and decryption of data.

Implementations§

Source§

impl State

Source

pub fn step_0(&mut self) -> Result<HandShakeFrame, Error>

Initiates the first step of the handshake process for the initiator.

Creates and sends the initial handshake message for the initiator. It is the first step in establishing a secure communication channel. Responders cannot perform this step.

nb: This method returns a HandShakeFrame but does not change the current state (self). The state remains State::HandShake(HandshakeRole::Initiator) until step_1 is called to advance the handshake process.

Source

pub fn step_1( &mut self, re_pub: [u8; 64], ) -> Result<(HandShakeFrame, Self), Error>

Processes the second step of the handshake process for the responder.

The responder receives the public key from the initiator, generates a response message containing the handshake frame, and prepares the NoiseCodec for transitioning the initiator state to transport mode in step_2.

nb: Returns a new state State::Transport but does not update the current state (self). The caller is responsible for updating the state, allowing for more flexible control over the handshake process as the caller decides what to do with this state.

Source

pub fn step_1_with_now_rng<R: Rng + CryptoRng>( &mut self, re_pub: [u8; 64], now: u32, rng: &mut R, ) -> Result<(HandShakeFrame, Self), Error>

Processes the second step of the handshake process for the responder given the current time and a custom random number generator.

See Self::step_1 for more details.

The current time and the custom random number generatorshould be provided in order to not implicitely rely on std and allow no_std environments to provide a hardware random number generator for example.

Source

pub fn step_2(&mut self, message: [u8; 234]) -> Result<Self, Error>

Processes the final step of the handshake process for the initiator.

Receives the response message from the responder containing the handshake frame, and transitions the state to transport mode. This finalizes the secure communication setup and enables full encryption and decryption in State::Transport mode.

nb: Directly updates the current state (self) to State::Transport, completing the handshake process.

Source

pub fn step_2_with_now( &mut self, message: [u8; 234], now: u32, ) -> Result<Self, Error>

Processes the final step of the handshake process for the initiator given the current system time.

See Self::step_2 for more details.

The current system time should be provided to avoid relying on std and allow no_std environments to use another source of time.

Source§

impl State

Source

pub fn not_initialized(role: &HandshakeRole) -> Self

Creates a new uninitialized handshake State.

Sets the codec to the initial state, State::NotInitialized, based on the provided handshake role. This state is used before the handshake process begins, and the handshake message size guides the codec on how much data to expect before advancing to the next step. The expected size of the handshake message is determined by whether the codec is acting as an initiator or responder.

Source

pub fn initialized(inner: HandshakeRole) -> Self

Initializes the codec state to State::HandShake mode with the given handshake role.

Transitions the codec into the handshake phase by accepting a HandshakeRole, which determines whether the codec is the initiator or responder in the handshake process. Once in State::HandShake mode, the codec begins negotiating cryptographic keys with the peer, eventually transitioning to the secure State::Transport phase.

The role passed to this method defines how the handshake proceeds:

Source

pub fn with_transport_mode(tm: NoiseCodec) -> Self

Transitions the codec state to State::Transport mode with the given NoiseCodec.

Finalizes the handshake process and transitions the codec into State::Transport mode, where full encryption and decryption are active. The codec uses the provided NoiseCodec to perform encryption and decryption for all communication in this mode, ensuring secure data transmission.

Once in State::Transport mode, the codec is fully operational for secure communication.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V