pub struct HandshakeState<D: DH, C: Cipher, H: Hash> { /* private fields */ }
Expand description

Noise handshake state.

Implementations

Initialize a handshake state.

If e is None, a new ephemeral key will be generated if necessary when write_message.

Setting Explicit Ephemeral Key

An explicit e should only be specified for testing purposes, or in fallback patterns. If you do pass in an explicit e, HandshakeState will use it as is and will not generate new ephemeral keys in write_message.

Calculate the size overhead of the next message.

Panics

If these is no more message to read/write, i.e., if the handshake is already completed.

Like write_message, but returns a Vec.

Takes a payload and write the generated handshake message to out.

Error Kinds
  • DH: DH operation failed.
  • NeedPSK: A PSK token is encountered but none is available.
Panics
  • If a required static key is not set.

  • If out.len() != payload.len() + self.get_next_message_overhead().

  • If it is not our turn to write.

  • If the handshake has already completed.

Takes a handshake message, process it and update our internal state, and write the encapsulated payload to out.

Error Kinds
  • DH: DH operation failed.
  • NeedPSK: A PSK token is encountered but none is available.
  • Decryption: Decryption failed.
Error Recovery

If read_message fails, the whole HandshakeState may be in invalid state and should not be used to read or write any further messages. (But get_re() and get_rs() is allowed.) In case error recovery is desirable, clone the HandshakeState before calling read_message.

Panics
  • If out.len() + self.get_next_message_overhead() != data.len().

    (Notes that this implies data.len() >= overhead.)

  • If a required static key is not set.

  • If it is not our turn to read.

  • If the handshake has already completed.

Similar to read_message, but returns result as a Vec.

In addition to possible errors from read_message, TooShort may be returned.

Push a PSK to the PSK-queue.

Panics

If the PSK-queue becomes longer than 4.

Whether handshake has completed.

Get handshake hash. Useful for e.g., channel binding.

Get ciphers that can be used to encrypt/decrypt further messages. The first CipherState is for initiator to responder, and the second for responder to initiator.

Should be called after handshake is completed.

Get remote static pubkey, if available.

Get remote semi-ephemeral pubkey.

Returns None if we do not know.

Useful for noise-pipes.

Get whether this HandshakeState is created as initiator.

Get handshake pattern this HandshakeState uses.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.