Skip to main content

PairSetupClient

Struct PairSetupClient 

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

A controller-side Pair Setup state machine over a single SRP-6a exchange.

Construct with new, drive with start then handle. The machine is transport-agnostic: it consumes and produces raw TLV8 bodies.

Implementations§

Source§

impl PairSetupClient

Source

pub fn new(setup_code: &str, controller: ControllerKeypair) -> Result<Self>

Create a Pair Setup client for setup_code, signing with controller.

setup_code is the accessory’s 8-digit setup code. It is accepted either already hyphenated ("123-45-678") or as bare digits ("12345678"); the digits are re-grouped into the canonical XXX-XX-XXX form HAP hashes as the SRP password. Any other input is used verbatim (the accessory will then reject the proof, which surfaces as a setup-code error in M4).

The SRP client ephemeral a is drawn from the OS CSPRNG; use new_with_private for a deterministic exchange in tests.

§Errors

Returns CryptoError::SrpBadParameters if the freshly generated SRP public ephemeral A is zero mod N (vanishingly unlikely).

Source

pub fn new_with_private( setup_code: &str, controller: ControllerKeypair, a: &[u8], ) -> Result<Self>

Create a Pair Setup client with a caller-supplied SRP private ephemeral a (the deterministic test seam).

Mirrors the crate-internal srp module’s with_private so a replay harness can reproduce an exchange exactly. a is the big-endian bytes of the SRP exponent.

§Errors

Returns CryptoError::SrpBadParameters if the resulting SRP public ephemeral A is zero mod N.

Source

pub fn start(&mut self) -> Vec<u8>

Produce the M1 request that starts Pair Setup.

The body is State=1, Method=PairSetup. Calling start advances the machine to await M2; calling it again re-emits M1 but does not reset any state already established by Self::handle.

Source

pub fn handle(&mut self, response: &[u8]) -> Result<PairSetupStep>

Consume an accessory response and advance the exchange.

Feed M2, then M4, then M6 in order; the return value is the next message to send (PairSetupStep::Send) until the final PairSetupStep::Done yields the AccessoryPairing.

§Errors

Returns a CryptoError if the response is malformed, omits a required field, carries an accessory Error TLV, fails SRP proof verification, fails AEAD authentication, or carries an accessory signature that does not verify. The machine then refuses further input.

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