pub struct LAContext { /* private fields */ }Expand description
Managed wrapper around Apple’s LAContext.
Implementations§
Source§impl LAContext
impl LAContext
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new authentication context.
§Errors
Returns an error if the Swift bridge fails to allocate the underlying LAContext.
Sourcepub fn invalidate(&self) -> Result<()>
pub fn invalidate(&self) -> Result<()>
Sourcepub fn can_evaluate_policy(&self, policy: LAPolicy) -> Result<bool>
pub fn can_evaluate_policy(&self, policy: LAPolicy) -> Result<bool>
Check whether a policy can be evaluated without prompting the user.
§Errors
Returns a mapped framework error when the policy is unavailable, or a bridge error if the request itself fails.
Sourcepub fn evaluate_policy(
&self,
policy: LAPolicy,
localized_reason: &str,
) -> Result<bool>
pub fn evaluate_policy( &self, policy: LAPolicy, localized_reason: &str, ) -> Result<bool>
Evaluate a policy with the supplied localized reason string.
§Errors
Returns a mapped framework or bridge error when evaluation fails.
Sourcepub unsafe fn evaluate_access_control_raw(
&self,
access_control: *const c_void,
operation: LAAccessControlOperation,
localized_reason: &str,
) -> Result<bool>
pub unsafe fn evaluate_access_control_raw( &self, access_control: *const c_void, operation: LAAccessControlOperation, localized_reason: &str, ) -> Result<bool>
Sourcepub fn localized_fallback_title(&self) -> Result<Option<String>>
pub fn localized_fallback_title(&self) -> Result<Option<String>>
Read the localized fallback title.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn set_localized_fallback_title(&self, title: Option<&str>) -> Result<()>
pub fn set_localized_fallback_title(&self, title: Option<&str>) -> Result<()>
Update the localized fallback title. Pass None to restore the default title.
§Errors
Returns an error if the title contains an interior NUL byte or the Swift bridge rejects the request.
Sourcepub fn localized_cancel_title(&self) -> Result<Option<String>>
pub fn localized_cancel_title(&self) -> Result<Option<String>>
Sourcepub fn set_localized_cancel_title(&self, title: Option<&str>) -> Result<()>
pub fn set_localized_cancel_title(&self, title: Option<&str>) -> Result<()>
Update the localized cancel title. Pass None to restore the default title.
§Errors
Returns an error if the title contains an interior NUL byte or the Swift bridge rejects the request.
Sourcepub fn localized_reason(&self) -> Result<String>
pub fn localized_reason(&self) -> Result<String>
Read the default localized reason used for authentication requests.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn set_localized_reason(&self, localized_reason: &str) -> Result<()>
pub fn set_localized_reason(&self, localized_reason: &str) -> Result<()>
Update the default localized reason used for authentication requests.
§Errors
Returns an error if the string contains an interior NUL byte or the Swift bridge rejects the request.
Sourcepub fn touch_id_authentication_allowable_reuse_duration(&self) -> Result<f64>
pub fn touch_id_authentication_allowable_reuse_duration(&self) -> Result<f64>
Read the allowable biometric reuse duration, in seconds.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn allowable_reuse_duration(&self) -> Result<f64>
pub fn allowable_reuse_duration(&self) -> Result<f64>
Backward-compatible alias for touch_id_authentication_allowable_reuse_duration.
§Errors
Propagates any error returned by touch_id_authentication_allowable_reuse_duration.
Sourcepub fn set_touch_id_authentication_allowable_reuse_duration(
&self,
duration: f64,
) -> Result<()>
pub fn set_touch_id_authentication_allowable_reuse_duration( &self, duration: f64, ) -> Result<()>
Update the allowable biometric reuse duration, in seconds.
§Errors
Returns an error if the value is negative, non-finite, or the Swift bridge rejects the request.
Sourcepub fn set_allowable_reuse_duration(&self, duration: f64) -> Result<()>
pub fn set_allowable_reuse_duration(&self, duration: f64) -> Result<()>
Backward-compatible alias for set_touch_id_authentication_allowable_reuse_duration.
§Errors
Propagates any error returned by set_touch_id_authentication_allowable_reuse_duration.
Sourcepub fn touch_id_authentication_maximum_allowable_reuse_duration() -> f64
pub fn touch_id_authentication_maximum_allowable_reuse_duration() -> f64
The framework-defined maximum reuse duration, in seconds.
Sourcepub fn interaction_not_allowed(&self) -> Result<bool>
pub fn interaction_not_allowed(&self) -> Result<bool>
Read whether interactive authentication UI is disabled.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn set_interaction_not_allowed(&self, value: bool) -> Result<()>
pub fn set_interaction_not_allowed(&self, value: bool) -> Result<()>
Enable or disable interactive authentication UI.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn biometry_type(&self) -> Result<BiometryType>
pub fn biometry_type(&self) -> Result<BiometryType>
Read the currently reported biometry type.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn evaluated_policy_domain_state(&self) -> Result<Option<Vec<u8>>>
pub fn evaluated_policy_domain_state(&self) -> Result<Option<Vec<u8>>>
Read the evaluated policy domain state bytes, if any are available.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn set_credential(&self, credential: &LACredential) -> Result<bool>
pub fn set_credential(&self, credential: &LACredential) -> Result<bool>
Set an application-provided credential for subsequent authentication operations.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn clear_credential(
&self,
credential_type: LACredentialType,
) -> Result<bool>
pub fn clear_credential( &self, credential_type: LACredentialType, ) -> Result<bool>
Remove any previously-supplied credential of the given type.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn is_credential_set(
&self,
credential_type: LACredentialType,
) -> Result<bool>
pub fn is_credential_set( &self, credential_type: LACredentialType, ) -> Result<bool>
Check whether a credential of the given type is currently stored on this context.
§Errors
Returns an error if the Swift bridge rejects the request.
Sourcepub fn domain_state(&self) -> Result<LADomainState>
pub fn domain_state(&self) -> Result<LADomainState>
Read the richer domainState snapshot available on macOS 15 and newer.
§Errors
Returns an error if the property is unavailable or the Swift bridge rejects the request.
Trait Implementations§
Source§impl AsyncContextExt for LAContext
Available on crate feature async only.
impl AsyncContextExt for LAContext
async only.Source§fn evaluate_policy_async(
&self,
policy: LAPolicy,
localized_reason: &str,
) -> Result<AsyncPolicyEvaluation>
fn evaluate_policy_async( &self, policy: LAPolicy, localized_reason: &str, ) -> Result<AsyncPolicyEvaluation>
Asynchronously evaluate a policy
Uses callback-based Swift FFI for true async operation.
§Arguments
policy- The authentication policy to evaluatelocalized_reason- A localized reason shown to the user
Source§unsafe fn evaluate_access_control_async(
&self,
access_control: *const c_void,
operation: LAAccessControlOperation,
localized_reason: &str,
) -> Result<AsyncAccessControlEvaluation>
unsafe fn evaluate_access_control_async( &self, access_control: *const c_void, operation: LAAccessControlOperation, localized_reason: &str, ) -> Result<AsyncAccessControlEvaluation>
Asynchronously evaluate an access control
Uses callback-based Swift FFI for true async operation.
§Arguments
access_control- ASecAccessControlreference (as raw pointer)operation- The access control operation to evaluatelocalized_reason- A localized reason shown to the user
§Safety
The access_control pointer must be a valid, properly initialized SecAccessControl reference.