Skip to main content

Auth

Struct Auth 

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

Gatekeeper for control actions: it issues pairing challenges and verifies commands.

Implementations§

Source§

impl Auth

Source

pub fn new(secret: impl Into<String>) -> Self

Creates an authenticator for a pairing secret.

§Arguments
  • secret - the canonical pairing secret string (the client normalizes a typed code to the same value).
§Returns

An authenticator with no sessions yet.

Source

pub fn generate_secret() -> String

Generates a fresh high-entropy pairing secret as lowercase hex.

§Returns

A 128-bit secret rendered as 32 hex characters.

Source

pub fn challenge(&self) -> Challenge

Starts a pairing exchange, returning a challenge and recording an unconfirmed session.

§Returns

The Challenge to send to the client.

Source

pub fn confirm(&self, session_id: &str, mac_hex: &str) -> Result<(), AuthError>

Confirms a pairing by checking the client proved it derived the session key.

§Arguments
  • session_id - the challenge’s session id.
  • mac_hex - HMAC(key, "confirm\n" + session_id) as lowercase hex.
§Returns

Ok(()) if the proof is valid and the session is now paired.

§Errors

AuthError::UnknownSession, AuthError::Expired, or AuthError::BadMac.

Source

pub fn verify_command( &self, session_id: &str, counter: u64, command: &str, mac_hex: &str, ) -> Result<(), AuthError>

Verifies an authenticated command and advances the session’s replay counter.

The MAC covers the counter and the exact command string, so the server checks the same bytes the client signed without re-serializing.

§Arguments
  • session_id - the paired session’s id.
  • counter - the strictly increasing per-session command counter.
  • command - the exact command payload string the client signed.
  • mac_hex - HMAC(key, counter + "\n" + command) as lowercase hex.
§Returns

Ok(()) if the command is authentic and fresh; the counter is then recorded.

§Errors

AuthError::UnknownSession, AuthError::NotPaired, AuthError::Expired, AuthError::Replayed, or AuthError::BadMac.

Auto Trait Implementations§

§

impl !Freeze for Auth

§

impl RefUnwindSafe for Auth

§

impl Send for Auth

§

impl Sync for Auth

§

impl Unpin for Auth

§

impl UnsafeUnpin for Auth

§

impl UnwindSafe for Auth

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.