[][src]Enum snow::Session

pub enum Session {
    Handshake(HandshakeState),
    Transport(TransportState),
    StatelessTransport(StatelessTransportState),
}

A state machine for the entire Noise session.

Enums provide a convenient interface as it's how Rust implements union structs, meaning this is a sized object.

Variants

Handshake(HandshakeState)

A session in the handshake stage (the starting state).

Transport(TransportState)

A session after having completed a handshake, in general-purpose trasport mode.

StatelessTransport(StatelessTransportState)

A session after having completed a handshake, in explicit-nonce trasport mode.

Methods

impl Session
[src]

pub fn was_write_payload_encrypted(&self) -> bool
[src]

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

This example is not tested
let mut session = Builder::new("Noise_NN_25519_AESGCM_SHA256".parse()?)
    .build_initiator()?;

// write message...

assert!(session.was_write_payload_encrypted());

pub fn is_handshake_finished(&self) -> bool
[src]

True if the handshake is finished and the Session state machine is ready to be transitioned to transport mode. This function also returns a vacuous true if already in transport mode.

Examples

This example is not tested
let mut session = Builder::new("Noise_NN_25519_AESGCM_SHA256".parse()?)
    .build_initiator()?;

if (session.is_handshake_finished()) {
    session = session.into_transport_mode()?;
}

pub fn is_initiator(&self) -> bool
[src]

Will report if the session has the initiator role (i.e. was built with Builder.build_initiator()).

#[must_use]
pub fn write_message(
    &mut self,
    payload: &[u8],
    output: &mut [u8]
) -> Result<usize, SnowError>
[src]

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 SnowError::Input if the size of the output exceeds the max message length in the Noise Protocol (65535 bytes).

#[must_use]
pub fn write_message_with_nonce(
    &self,
    nonce: u64,
    payload: &[u8],
    output: &mut [u8]
) -> Result<usize, SnowError>
[src]

Construct a message from payload with an explicitly provided nonce and write it to the output buffer.

Returns the size of the written payload.

Errors

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

Will result in SnowError::StateProblem if not in stateless transport mode.

#[must_use]
pub fn read_message(
    &mut self,
    input: &[u8],
    payload: &mut [u8]
) -> Result<usize, SnowError>
[src]

Reads a noise message from input

Returns the size of the payload written to payload.

Errors

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

Panics

This function will panic if there is no key, or if there is a nonce overflow.

#[must_use]
pub fn read_message_with_nonce(
    &self,
    nonce: u64,
    input: &[u8],
    payload: &mut [u8]
) -> Result<usize, SnowError>
[src]

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 SnowError::Input if the size of the output exceeds the max message length in the Noise Protocol (65535 bytes).

Will result in SnowError::StateProblem if not in stateless transport mode.

#[must_use]
pub fn rekey_outgoing(&mut self) -> Result<(), SnowError>
[src]

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.

Errors

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

#[must_use]
pub fn rekey_incoming(&mut self) -> Result<(), SnowError>
[src]

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.

Errors

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

#[must_use]
pub fn rekey_manually(
    &mut self,
    initiator: Option<&[u8]>,
    responder: Option<&[u8]>
) -> Result<(), SnowError>
[src]

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

Errors

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

pub fn receiving_nonce(&self) -> Result<u64, SnowError>
[src]

Get the forthcoming inbound nonce value.

Errors

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

pub fn sending_nonce(&self) -> Result<u64, SnowError>
[src]

Get the forthcoming outbound nonce value.

Errors

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

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

Get the remote static key that was possibly encrypted in the first payload.

Returns a slice of length Dh.pub_len() (i.e. DHLEN for the chosen DH function).

pub fn get_handshake_hash(&self) -> Result<&[u8], SnowError>
[src]

Get the handshake hash.

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

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

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 SnowError::Input if the PSK is not the right length or the location is out of bounds. Will result in SnowError::State if in transport mode.

pub fn into_transport_mode(self) -> Result<Self, SnowError>
[src]

Transition the session into transport mode. This can only be done once the handshake has finished.

Consumes the previous state, and returns the new transport state object, thereby freeing any material only used during the handshake phase.

Errors

Will result in SnowError::State if the handshake is not finished.

Examples

This example is not tested
let mut session = Builder::new("Noise_NN_25519_AESGCM_SHA256".parse()?)
                  .build_initiator()?;

// ... complete handshake ...

session = session.into_transport_mode()?;

pub fn into_stateless_transport_mode(self) -> Result<Self, SnowError>
[src]

Transition the session into stateless (explicit nonce) transport mode. This is useful when using Noise over lossy transports. Like into_transport_mode(), this can only be done once the handshake has finished.

Consumes the previous state, and returns the new transport state object, thereby freeing any material only used during the handshake phase.

Errors

Will result in SnowError::State if the handshake is not finished.

Examples

This example is not tested
let mut session = Builder::new("Noise_NN_25519_AESGCM_SHA256".parse()?)
                  .build_initiator()?;

// ... complete handshake ...

session = session.into_stateless_transport_mode()?;

Trait Implementations

impl Debug for Session
[src]

Auto Trait Implementations

impl Send for Session

impl Sync for Session

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same for T

type Output = T

Should always be Self