Skip to main content

ServerHandshake

Struct ServerHandshake 

Source
pub struct ServerHandshake { /* private fields */ }
Expand description

Server (whisker run) side of the handshake, between the server proof and the client proof

The dev server passes the first text message it receives to respond, sends the returned proof, and then sends nothing else until finish accepts the client’s proof. The dev runtime relies on that silence to bound how much it reads before authentication.

§Example

use whisker_dev_protocol::{Error, ServerHandshake};

// A pre-handshake hello that carries the secret is not a challenge.
let legacy = r#"{"kind":"hello","aslr_reference":1,"token":"secret"}"#;
assert!(matches!(
    ServerHandshake::respond("secret", legacy),
    Err(Error::MalformedHandshake(_))
));

Implementations§

Source§

impl ServerHandshake

Source

pub fn respond(secret: &str, challenge: &str) -> Result<(Self, String), Error>

Check a client challenge and return the server proof text to send

Fails with Error::UnsupportedVersion for a challenge from another protocol version and Error::MalformedHandshake for anything that is not a challenge.

Source

pub fn finish(self, client_proof: &str) -> Result<Session, Error>

Verify the client’s proof and return the established session

Fails with Error::InvalidClientProof when the client does not hold the same secret.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.