Struct PairingGuard
pub struct PairingGuard { /* private fields */ }Implementations§
Source§impl PairingGuard
impl PairingGuard
pub fn new(require_pairing: bool, existing_tokens: &[String]) -> Self
Sourcepub fn pairing_code(&self) -> Option<String>
pub fn pairing_code(&self) -> Option<String>
The one-time pairing code (generated only on first startup when no tokens exist).
Sourcepub fn require_pairing(&self) -> bool
pub fn require_pairing(&self) -> bool
Whether pairing is required at all.
Sourcepub async fn try_pair(
&self,
code: &str,
client_id: &str,
) -> Result<Option<String>, u64>
pub async fn try_pair( &self, code: &str, client_id: &str, ) -> Result<Option<String>, u64>
Attempt to pair with the given code. Returns a bearer token on success.
Returns Err(lockout_seconds) if locked out due to brute force.
client_id identifies the client for per-client lockout accounting.
Sourcepub fn is_authenticated(&self, token: &str) -> bool
pub fn is_authenticated(&self, token: &str) -> bool
Check if a bearer token is valid (compares against stored hashes).
Sourcepub fn is_paired(&self) -> bool
pub fn is_paired(&self) -> bool
Returns true if the gateway is already paired (has at least one token).
pub fn revoke_token(&self, token: &str) -> bool
Sourcepub fn revoke_token_hash(&self, token_hash: &str) -> bool
pub fn revoke_token_hash(&self, token_hash: &str) -> bool
Revoke a paired token by its SHA-256 hash. Returns true if removed.
pub fn revoke_all_tokens(&self) -> usize
Sourcepub fn generate_new_pairing_code(&self) -> Option<String>
pub fn generate_new_pairing_code(&self) -> Option<String>
Generate a new pairing code that pairs an additional client.
Does not revoke existing tokens. To rotate a compromised token,
pair with revoke_token/revoke_token_hash + a config persist pass.
pub fn generate_pairing_code_if_vacant( &self, ) -> Result<String, GeneratePairingCodeError>
Sourcepub fn token_hash(token: &str) -> String
pub fn token_hash(token: &str) -> String
Get the token hash for a given plaintext token (for device registry lookup).
Sourcepub fn authenticate_and_hash(&self, token: &str) -> Option<String>
pub fn authenticate_and_hash(&self, token: &str) -> Option<String>
Check if a token is paired and return its hash.
Trait Implementations§
Source§impl Clone for PairingGuard
impl Clone for PairingGuard
Source§fn clone(&self) -> PairingGuard
fn clone(&self) -> PairingGuard
1.0.0 (const: unstable) · §fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PairingGuard
impl !RefUnwindSafe for PairingGuard
impl Send for PairingGuard
impl Sync for PairingGuard
impl Unpin for PairingGuard
impl UnsafeUnpin for PairingGuard
impl !UnwindSafe for PairingGuard
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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