| Crates.io | datp |
| lib.rs | datp |
| version | 0.1.1 |
| created_at | 2025-11-30 13:35:34.866761+00 |
| updated_at | 2025-11-30 13:53:28.78589+00 |
| description | datp - library for totp |
| homepage | https://akaruinekooff.github.io/datp/ |
| repository | https://github.com/akaruinekooff/datp |
| max_upload_size | |
| id | 1958227 |
| size | 24,339 |
datp is a lightweight Rust library for working with TOTP (Time-based One-Time Password) and generating QR codes for two-factor authentication.
Add to Cargo.toml:
[dependencies]
datp = "0.1.0"
use datp::generate_totp_secret;
let secret = generate_totp_secret(10);
println!("TOTP secret: {}", secret);
use datp::totp_raw_now;
let secret = "JBSWY3DPEHPK3PXP";
let code = totp_raw_now(secret, 30, 0).unwrap();
println!("Current TOTP code: {}", code);
use datp::totp_raw;
let secret = "JBSWY3DPEHPK3PXP";
let code = totp_raw(secret, 30, 0, 1_388_865_600).unwrap();
println!("TOTP code at specific time: {}", code);
use datp::{totp_qr_svg, TotpQrConfig};
use qrcode::EcLevel;
use qrcode::Version;
let secret = "JBSWY3DPEHPK3PXP";
let config = TotpQrConfig {
account_name: "user@example.com",
issuer: "MyApp",
dark_color: "#000080",
light_color: "#ffffcc",
min_dimension: 250,
version: Version::Normal(5),
ec_level: EcLevel::M,
};
let svg = totp_qr_svg(secret, &config);
std::fs::write("totp.svg", svg).unwrap();
Hmac<Sha1> for TOTP generation.