Expand description
§localauthentication-rs
Safe Rust bindings for Apple’s LocalAuthentication framework on macOS.
Status: v0.2.1 expands coverage across
LAContext,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 localauthentication::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let context = LAContext::new()?;
context.set_interaction_not_allowed(true)?;
context.set_localized_reason("inspect local authentication state")?;
match context.can_evaluate_policy(LAPolicy::DeviceOwnerAuthenticationWithBiometrics) {
Ok(true) => {
println!("biometry: {:?}", context.biometry_type()?);
println!("reason: {}", context.localized_reason()?);
}
Ok(false) => println!("policy unavailable without a framework error"),
Err(error) => println!("policy unavailable: {error}"),
}
Ok(())
}§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)
§Examples
The crate ships numbered examples for every logical area:
01_smoke—LAContext, policies, credentials, and domain state02_policy_catalog— policy availability across biometric and companion modes03_error_codes—LAErrorand domain/code mapping04_credentials—LACredentialhelpers05_authentication_requirements— requirement builders andLARightconstruction06_rights— right state/tag/preflight/deauthorize flow07_right_store— sharedLARightStorepersistence entry points08_persisted_right—LAPersistedRight,LASecret, andLAPrivateKey09_public_key—LAPublicKeyexport plusLAPrivateKeyverify/encrypt/key-exchange capability checks10_environment—LAEnvironment, observer registration, and mechanism snapshots
Run the full verification matrix with:
cargo clippy --all-targets -- -D warnings
cargo test
for ex in examples/*.rs; do cargo run --example "$(basename "$ex" .rs)"; doneFor the header-by-header audit, see COVERAGE.md.
§License
Licensed under either of Apache-2.0 or MIT at your option.
§API documentation
Safe Rust bindings for Apple’s LocalAuthentication.framework on macOS.
Re-exports§
pub use la_authentication_requirement::LAAuthenticationRequirement;pub use la_authentication_requirement::LABiometryFallbackRequirement;pub use la_context::BiometryType;pub use la_context::LAAccessControlOperation;pub use la_context::LACompanionType;pub use la_context::LAContext;pub use la_context::LADomainState;pub use la_context::LADomainStateBiometry;pub use la_context::LADomainStateCompanion;pub use la_credential::LACredential;pub use la_credential::LACredentialType;pub use la_environment::LAEnvironment;pub use la_environment::LAEnvironmentMechanism;pub use la_environment::LAEnvironmentMechanismBiometry;pub use la_environment::LAEnvironmentMechanismCompanion;pub use la_environment::LAEnvironmentMechanismUserPassword;pub use la_environment::LAEnvironmentObserver;pub use la_environment::LAEnvironmentObserverRegistration;pub use la_environment::LAEnvironmentState;pub use la_error::LAError;pub use la_error::LocalAuthenticationError;pub use la_error::Result;pub use la_error::LA_ERROR_DOMAIN;pub use la_persisted_right::LAPersistedRight;pub use la_persisted_right::LAPrivateKey;pub use la_persisted_right::LASecret;pub use la_policy::LAPolicy;pub use la_policy::Policy;pub use la_public_key::LAPublicKey;pub use la_public_key::SecKeyAlgorithm;pub use la_public_key::SecKeyExchangeParameters;pub use la_right::LARight;pub use la_right::LARightState;pub use la_right_store::LARightStore;
Modules§
- context
- Backward-compatible re-exports for the original
contextmodule. - error
- Backward-compatible re-exports for the original
errormodule. - ffi
- Raw FFI declarations matching the Swift
la_*bridge exports. - la_
authentication_ requirement LAAuthenticationRequirementandLABiometryFallbackRequirementwrappers.- la_
context LAContextand relatedLocalAuthenticationvalue types.- la_
credential - Application-provided credential helpers for
LAContext. - la_
environment LAEnvironmentobserver, state, and mechanism wrappers.- la_
error - Errors produced by the
LocalAuthenticationbridge. - la_
persisted_ right LAPersistedRight,LAPrivateKey, andLASecretwrappers.- la_
policy LAPolicyvalues supported byLAContext.- la_
public_ key LAPublicKeywrappers.- la_
right LARightwrappers.- la_
right_ store LARightStorewrappers.- prelude
- Common imports for users of this crate.