Skip to main content

HapPairSetupSrpServer

Struct HapPairSetupSrpServer 

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

The accessory (server) half of HAP Pair Setup’s SRP-6a exchange.

This is the counterpart of PairSetupClient’s SRP portion (M2–M4), packaged for a reference accessory to drive Pair Setup without touching the crate-internal SRP generics: it fixes the HAP group (RFC 5054 Appendix A 3072-bit, g = 5), the hash (SHA-512), and the SRP username ("Pair-Setup"), and normalises the setup code exactly as PairSetupClient does so the two derive the same verifier.

Construct one per pairing attempt with new (a fresh random salt and private ephemeral b), send M2 as State=2, Salt=salt, PublicKey= b_pub_bytes, then on M3 compute the session key from the controller’s A with session_key and verify its proof with verify_m1_prove_m2.

Implementations§

Source§

impl HapPairSetupSrpServer

Source

pub fn new(setup_code: &str) -> Result<(Self, Vec<u8>)>

Build a Pair Setup SRP server for setup_code, returning it together with the 16-byte SRP salt to send in M2.

setup_code is accepted hyphenated ("123-45-678") or as bare digits ("12345678"); it is normalised to the canonical XXX-XX-XXX form — identically to PairSetupClient::new — before use as the SRP password. The salt and the private ephemeral b are drawn from the OS CSPRNG.

§Errors

Returns CryptoError only if the embedded HAP group is rejected (which the fixed constant never triggers).

Source

pub fn b_pub_bytes(&self) -> Vec<u8>

PAD(B) — the accessory’s SRP public ephemeral in wire form (384 bytes), sent as PublicKey in M2.

Source

pub fn session_key(&self, a_pub_bytes: &[u8]) -> Result<Vec<u8>>

Compute the SRP session key K from the controller’s public ephemeral A (the PublicKey bytes received in M3).

§Errors

Returns CryptoError::SrpBadParameters if A is zero mod N, or CryptoError::SrpProofMismatch if the scrambler u is zero.

Source

pub fn verify_m1_prove_m2( &self, a_pub_bytes: &[u8], m1: &[u8], ) -> Result<Vec<u8>>

Verify the controller’s proof M1 (from M3) against its public ephemeral A, returning the accessory proof M2 to send in M4.

The session key is recomputed from A internally, so this is self-contained; callers that also need K (to derive the M5/M6 keys) should call session_key once and keep the result.

§Errors

Returns CryptoError::SrpProofMismatch if M1 does not verify (the wrong setup code), or the errors of session_key.

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.