Crate lib2fas

Crate lib2fas 

Source
Expand description

§lib2fas

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. It also provides tools for utilities for decryption, fuzzy matching, JSON5 parsing, and more.

§Features

  • 2FA Data Management: Provides data structures to represent and query OTPs, 2FA services, and storage.
  • Fuzzy Matching: Functions for string similarity comparisons, useful for searching and filtering.
  • JSON5 Support: Utilities for parsing and serializing JSON5 configurations, synchronously and asynchronously.
  • Helper Utilities: Common functions and abstractions for efficient processing.

§Example

Here’s a quick example of loading and working with 2FA services:

use lib2fas::load_services;

#[tokio::main]
async fn main() {
    // or `load_services_blocking` if you can't use async.
    let result = load_services("path/to/services.2fas", Some("passphrase")).await;
    match result {
        Ok(storage) => {
            println!("Loaded {} services", storage.len());

            if let Some(service) = storage.first() {
                println!("First service: {}", service.name);
                if let Some(otp) = service.totp() {
                    println!("Current OTP: {}", otp);
                } else {
                    println!("OTP generation not available for this service.");
                }
            } else {
                println!("No services found.");
            }
        },
        Err(err) => {
            eprintln!("Failed to load services: {}", err);
        },
    }
}

§Modules

  • decrypt: Functions for securely decrypting 2FA data.
  • fuzzy: Utilities for fuzzy string matching.
  • helpers: Common helper functions.
  • json5_support: Support for JSON5 parsing and serialization.
  • lib2fas: Core components and types for managing 2FA services.

§Re-Exports

Re-exports§

pub use crate::lib2fas::load_services;
pub use crate::lib2fas::load_services_blocking;
pub use crate::lib2fas::OTPDetails;
pub use crate::lib2fas::TwoFactorAuthDetails;
pub use crate::lib2fas::TwoFactorStorage;

Modules§

decrypt
Provides functionality for decrypting data, including AES-256-GCM decryption with PBKDF2.
fuzzy
Contains utilities for fuzzy string matching and similarity calculations.
helpers
Offers helper functions and utilities used across the library.
json5_support
Provides support for working with JSON5 format, including serialization and deserialization.
lib2fas
Defines the core types, traits, and functions of the lib2fas library.