Crates.io | minotp |
lib.rs | minotp |
version | 1.2.1 |
source | src |
created_at | 2024-02-04 16:42:51.663024 |
updated_at | 2024-11-11 00:47:32.337229 |
description | Simple OTP library for Rust. |
homepage | https://github.com/chardoncs/minotp |
repository | https://github.com/chardoncs/minotp.git |
max_upload_size | |
id | 1126500 |
size | 21,790 |
Simple OTP library for Rust.
Add minotp
into your project.
cargo add minotp@1
Also all hash libraries you want (e.g., SHA1 of Rust Crypto).
cargo add sha1
use minotp::*;
use sha1::Sha1;
let secret = b"test";
let totp = Totp::<Sha1>::from_bytes(secret, 30).unwrap();
// Get remaining seconds
let _remaining_seconds = totp.remaining_sec();
// Get token as a 6-digit owned string
let _token = totp.gen_6_str();
// -- snip -- //
Use an encoding crate to decode a Base32 encoded secret if you have to deal with one.
For example, using data_encoding
.
use data_encoding::BASE32;
use minotp::*;
use sha1::Sha1;
let secret_base32_str = "ORSXG5A=";
let secret = BASE32.decode(secret_base32_str.as_bytes()).unwrap();
let totp = Totp::<Sha1>::from_bytes(&secret, 30).unwrap();
let _token = totp.gen_6_str();
// -- snip -- //
You must be kidding. Fire an issue right now if you found one!