pub struct HandshakeState { /* private fields */ }Expand description
Handshake state for Noise IK and XK patterns.
Implementations§
Source§impl HandshakeState
impl HandshakeState
Sourcepub fn new_initiator(static_keypair: Keypair, remote_static: PublicKey) -> Self
pub fn new_initiator(static_keypair: Keypair, remote_static: PublicKey) -> Self
Create a new IK handshake as initiator.
The initiator knows the responder’s static key and will send first. Used by FMP (link layer).
Sourcepub fn new_responder(static_keypair: Keypair) -> Self
pub fn new_responder(static_keypair: Keypair) -> Self
Create a new IK handshake as responder.
The responder does NOT know the initiator’s static key - it will be learned from message 1. Used by FMP (link layer).
Sourcepub fn new_xk_initiator(
static_keypair: Keypair,
remote_static: PublicKey,
) -> Self
pub fn new_xk_initiator( static_keypair: Keypair, remote_static: PublicKey, ) -> Self
Create a new XK handshake as initiator.
The initiator knows the responder’s static key. XK defers the initiator’s static key reveal to msg3. Used by FSP (session layer).
Sourcepub fn new_xk_responder(static_keypair: Keypair) -> Self
pub fn new_xk_responder(static_keypair: Keypair) -> Self
Create a new XK handshake as responder.
The responder does NOT know the initiator’s static key - it will be learned from message 3. Used by FSP (session layer).
Sourcepub fn role(&self) -> HandshakeRole
pub fn role(&self) -> HandshakeRole
Get our role.
Sourcepub fn progress(&self) -> HandshakeProgress
pub fn progress(&self) -> HandshakeProgress
Get current progress.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if handshake is complete.
Sourcepub fn remote_static(&self) -> Option<&PublicKey>
pub fn remote_static(&self) -> Option<&PublicKey>
Get the remote static key (available after message 1 for responder).
Sourcepub fn set_local_epoch(&mut self, epoch: [u8; 8])
pub fn set_local_epoch(&mut self, epoch: [u8; 8])
Set the local startup epoch for restart detection.
Sourcepub fn remote_epoch(&self) -> Option<[u8; 8]>
pub fn remote_epoch(&self) -> Option<[u8; 8]>
Get the remote peer’s startup epoch (available after processing their message).
Sourcepub fn write_message_1(&mut self) -> Result<Vec<u8>, NoiseError>
pub fn write_message_1(&mut self) -> Result<Vec<u8>, NoiseError>
Write message 1 (initiator only).
Message 1 contains:
- e: ephemeral public key (33 bytes)
- encrypted s: our static public key encrypted (33 + 16 = 49 bytes)
- encrypted epoch: startup epoch for restart detection (8 + 16 = 24 bytes)
Total: 106 bytes
Sourcepub fn read_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>
pub fn read_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>
Read message 1 (responder only).
Processes the initiator’s first message and learns their identity and epoch.
Sourcepub fn write_message_2(&mut self) -> Result<Vec<u8>, NoiseError>
pub fn write_message_2(&mut self) -> Result<Vec<u8>, NoiseError>
Write message 2 (responder only).
Message 2 contains:
- e: ephemeral public key (33 bytes)
- encrypted epoch: startup epoch for restart detection (8 + 16 = 24 bytes)
Total: 57 bytes
Sourcepub fn read_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>
pub fn read_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>
Read message 2 (initiator only).
Processes the responder’s message and completes the handshake.
Sourcepub fn write_xk_message_1(&mut self) -> Result<Vec<u8>, NoiseError>
pub fn write_xk_message_1(&mut self) -> Result<Vec<u8>, NoiseError>
Write XK message 1 (initiator only).
XK msg1: -> e, es
- e: ephemeral public key (33 bytes)
- es: DH(e_priv, rs_pub), mix_key
Total: 33 bytes (ephemeral only — no static, no epoch)
Sourcepub fn read_xk_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>
pub fn read_xk_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>
Read XK message 1 (responder only).
Processes the initiator’s first message. Does NOT learn initiator’s identity (that comes in msg3).
Sourcepub fn write_xk_message_2(&mut self) -> Result<Vec<u8>, NoiseError>
pub fn write_xk_message_2(&mut self) -> Result<Vec<u8>, NoiseError>
Write XK message 2 (responder only).
XK msg2: <- e, ee + encrypted epoch
- e: ephemeral public key (33 bytes)
- ee: DH(e_priv, re_pub), mix_key
- encrypted epoch (24 bytes)
Total: 57 bytes
Sourcepub fn read_xk_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>
pub fn read_xk_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>
Read XK message 2 (initiator only).
Processes the responder’s message and extracts the responder’s epoch. Does NOT complete the handshake — msg3 still needed.
Sourcepub fn write_xk_message_3(&mut self) -> Result<Vec<u8>, NoiseError>
pub fn write_xk_message_3(&mut self) -> Result<Vec<u8>, NoiseError>
Write XK message 3 (initiator only).
XK msg3: -> s, se + encrypted epoch
- s: encrypt_and_hash(s_pub) — encrypted static (49 bytes)
- se: DH(s_priv, re_pub), mix_key
- encrypted epoch (24 bytes)
Total: 73 bytes
Sourcepub fn read_xk_message_3(&mut self, message: &[u8]) -> Result<(), NoiseError>
pub fn read_xk_message_3(&mut self, message: &[u8]) -> Result<(), NoiseError>
Read XK message 3 (responder only).
Processes the initiator’s encrypted static key and epoch. After this, the responder learns the initiator’s identity.
Sourcepub fn into_session(self) -> Result<NoiseSession, NoiseError>
pub fn into_session(self) -> Result<NoiseSession, NoiseError>
Complete the handshake and return a NoiseSession.
Must be called after the handshake is complete.
Sourcepub fn handshake_hash(&self) -> [u8; 32]
pub fn handshake_hash(&self) -> [u8; 32]
Get the handshake hash (for channel binding, available after complete).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HandshakeState
impl RefUnwindSafe for HandshakeState
impl Send for HandshakeState
impl Sync for HandshakeState
impl Unpin for HandshakeState
impl UnsafeUnpin for HandshakeState
impl UnwindSafe for HandshakeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more