localauthentication-rs
Safe Rust bindings for Apple's LocalAuthentication framework on macOS.
Status: v0.3.0 adds async API support (gated behind the
asyncfeature) for executor-agnostic policy and access control evaluation. The synchronous API remains at v0.2.1 coverage acrossLAContext,LAPolicy,LAError,LACredential,LAAuthenticationRequirement,LARight,LARightStore,LAPersistedRight,LAPublicKey,LAPrivateKey,LASecret, and the macOS 15LAEnvironmentobserver/state surface.
Platform notes
- The Rust crate is macOS-focused and links the system
LocalAuthentication.framework. - The Swift bridge now targets macOS 13+.
LAContext::domain_state()plus theLAEnvironment::{current_user, state, add_observer}surface are macOS 15+ APIs.- Persisted-right and key APIs can require signing or entitlements; the examples and tests treat
OSStatus -34018as an expected environment limitation. LAPrivateKey::exchange_keys_with_public_keyusesSecKeyExchangeParametersfor the requested derived-key length and optional shared-info KDF context.
Quick start
use *;
Highlights
LAContextlifecycle, policy preflight/evaluation, credential injection, domain-state snapshots, and raw access-control evaluationLAPolicy,LAError,LA_ERROR_DOMAIN,BiometryType, andLACompanionTypeLAAuthenticationRequirementandLABiometryFallbackRequirementbuilders for rightsLARightandLARightStorefor in-memory and persisted authorization flowsLAPersistedRight,LASecret,LAPrivateKey,LAPublicKey,SecKeyAlgorithm, andSecKeyExchangeParametershelpers for persisted secrets and asymmetric-key operationsLAEnvironment,LAEnvironmentObserver,LAEnvironmentState, and the environment mechanism subclasses for macOS 15 environment snapshots and change notifications- Backward-compatible aliases for the v0.1.x surface (
Policy,LocalAuthenticationError,context, anderror) - Async API (gated behind
asyncfeature): executor-agnostic async wrappers for policy and access control evaluation viaAsyncContextExttrait
Async API
When the async feature is enabled, the async_api module provides executor-agnostic async methods for authentication:
use *;
use AsyncContextExt;
The async API:
- Works with any async runtime (Tokio, async-std, smol, pollster, etc.)
- Uses callback-based Swift FFI for true async operations
- Provides
AsyncContextExttrait with async variants ofevaluate_policy_asyncandevaluate_access_control_async - Returns futures that resolve to
Result<bool, LAError>
See examples/02_async_policy.rs for a complete example.
Examples
The crate ships numbered examples for every logical area:
01_smoke—LAContext, policies, credentials, and domain state02_async_policy— async policy evaluation usingAsyncLAContext(requiresasyncfeature)03_policy_catalog— policy availability across biometric and companion modes04_error_codes—LAErrorand domain/code mapping05_credentials—LACredentialhelpers06_authentication_requirements— requirement builders andLARightconstruction07_rights— right state/tag/preflight/deauthorize flow08_right_store— sharedLARightStorepersistence entry points09_persisted_right—LAPersistedRight,LASecret, andLAPrivateKey10_public_key—LAPublicKeyexport plusLAPrivateKeyverify/encrypt/key-exchange capability checks11_environment—LAEnvironment, observer registration, and mechanism snapshots
Run the full verification matrix with:
for; do ; done
For the header-by-header audit, see COVERAGE.md.
License
Licensed under either of Apache-2.0 or MIT at your option.