Struct noise_protocol::HandshakeState
[−]
[src]
pub struct HandshakeState<D: DH, C: Cipher, H: Hash> { /* fields omitted */ }
Noise handshake state.
Notes
HandshakeState
does not generate new ephemeral keys when seeing
a E
token. Users of HandshakeState
are responsible for
generating fresh ephemeral keys.
Panics
HandshakeState
must be used correctly, or its methods will likely panic:
Keys required by the handshake pattern must be set;
write_message
and read_message
must be called in right turns;
write_message
and read_message
must not be called after completed
.
Methods
impl<D, C, H> HandshakeState<D, C, H> where
D: DH,
C: Cipher,
H: Hash,
[src]
D: DH,
C: Cipher,
H: Hash,
fn get_name(has_psk: bool, pattern_name: &str) -> String
Get protocol name, e.g. Noise_IK_25519_ChaChaPoly_BLAKE2s.
fn new(
pattern: HandshakePattern,
is_initiator: bool,
prologue: &[u8],
psk: Option<&[u8]>,
s: Option<D::Key>,
e: Option<D::Key>,
rs: Option<D::Pubkey>,
re: Option<D::Pubkey>
) -> Self
pattern: HandshakePattern,
is_initiator: bool,
prologue: &[u8],
psk: Option<&[u8]>,
s: Option<D::Key>,
e: Option<D::Key>,
rs: Option<D::Pubkey>,
re: Option<D::Pubkey>
) -> Self
Initialize a handshake state.
fn write_message(&mut self, payload: &[u8]) -> Vec<u8>
Takes a payload and return a packet that you should send to the peer.
fn read_message(&mut self, data: &[u8]) -> Result<Vec<u8>, NoiseError>
Update handshake state and get payload, given a packet.
If the packet fails to decrypt, the whole HandshakeState may be in invalid state, and
should not be used any more. Expect to get_re
before falling back to XXfallback
.
fn completed(&self) -> bool
Whether handshake has completed.
fn get_hash(&self) -> &[u8]
Get handshake hash. Useful for e.g., channel binding.
Should be called after handshake is completed()
.
fn get_ciphers(&self) -> (CipherState<C>, CipherState<C>)
Get ciphers that can be used to encrypt/decrypt furthur messages.
The first CiperState
is for initiator to responder, and the second for responder
to initiator.
Should be called after handshake is completed()
.
fn get_rs(&self) -> Option<D::Pubkey>
Get remote static pubkey, if available.
fn get_re(&self) -> Option<D::Pubkey>
Get remote semi-ephemeral pubkey.
Returns None
if we do not know.
Useful for noise-pipes.