| Crates.io | lib2fas |
| lib.rs | lib2fas |
| version | 0.1.2 |
| created_at | 2025-01-10 21:17:30.686869+00 |
| updated_at | 2025-01-13 21:47:20.098927+00 |
| description | Unofficial implementation of 2fas for Rust (as a library). |
| homepage | |
| repository | https://github.com/robinvandernoord/lib2fas-rust |
| max_upload_size | |
| id | 1511758 |
| size | 97,433 |
lib2fas is an unofficial implementation of the 2fas platform for Rust, providing tools for
managing and interacting with two-factor authentication (2FA) services as a library.
Add lib2fas to your Cargo.toml:
cargo add lib2fas
Or add it manually with a specific version:
# Cargo.toml
[dependencies]
lib2fas = "x.y.z"
use lib2fas::load_services;
#[tokio::main]
async fn main() {
// or `load_services_blocking` if you can't use async.
let maybe_storage = load_services("path/to/services.2fas", Some("your-passphrase")).await;
match maybe_storage {
Ok(storage) => {
println!("Loaded {} services", storage.len());
if let Some(service) = storage.find_first("example-service") {
println!("Found service: {}", service.name);
if let Some(otp) = service.totp() {
println!("Current OTP: {}", otp);
}
if let Some(next_otp) = service.totp_next() {
println!("Next OTP: {}", next_otp);
}
if let Some(current_otp_u32) = service.totp_u32() {
println!("Current OTP (as number): {}", current_otp_u32);
}
} else {
println!("Service not found.");
}
}
Err(err) => {
eprintln!("Failed to load services: {}", err);
}
}
}
Run tests with output to stdout:
cargo test -- --nocapture
Run tests with coverage output:
cargo tarpaulin --out Html
For more detailed information, visit docs.rs/lib2fas.
The source code is available on GitHub.