#otp #hotp #totp #password #sha-1

no-std minotp

Simple OTP library for Rust

4 stable releases

1.2.1 Nov 11, 2024
1.1.0 Feb 9, 2024
1.0.0 Feb 5, 2024
0.1.1 Feb 4, 2024
0.1.0 Feb 4, 2024

#1095 in Cryptography

Download history 241/week @ 2024-11-08 28/week @ 2024-11-15 3/week @ 2024-11-22 3/week @ 2024-12-06 152/week @ 2025-02-14

152 downloads per month

MIT license

18KB
239 lines

minotp

GitHub Release

Simple OTP library for Rust.

Usage

Installation

Add minotp into your project.

cargo add minotp@1

Also all hash libraries you want (e.g., SHA1 of Rust Crypto).

cargo add sha1

TOTP (commonly used)

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 -- //

Found any bug?

You must be kidding. Fire an issue right now if you found one!

Dependencies

~670KB
~16K SLoC