Enum snow::Session[][src]

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

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

Methods

impl Session
[src]

If the payload will be encrypted or not. In a future version of Snow, this interface may change to more proactively prevent unauthenticated, plaintext payloads during handshakes.

See Payload Security Properties for more information.

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()?;
}

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).

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.

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.

Get the forthcoming inbound nonce value.

Errors

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

Get the forthcoming outbound nonce value.

Errors

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

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).

Get the handshake hash.

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

Set the forthcoming incoming nonce value.

Errors

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

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.

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()?;

Trait Implementations

impl Debug for Session
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Session

impl !Sync for Session