Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chardoncs/minotp
Dead simple OTP library for Rust.
https://github.com/chardoncs/minotp
cryptography hotp one-time-password otp rust totp
Last synced: 25 days ago
JSON representation
Dead simple OTP library for Rust.
- Host: GitHub
- URL: https://github.com/chardoncs/minotp
- Owner: chardoncs
- License: apache-2.0
- Created: 2024-02-04T11:10:57.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-02-09T03:47:00.000Z (9 months ago)
- Last Synced: 2024-10-12T23:42:31.528Z (about 1 month ago)
- Topics: cryptography, hotp, one-time-password, otp, rust, totp
- Language: Rust
- Homepage: https://crates.io/crates/minotp
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# minotp
![GitHub Release](https://img.shields.io/github/v/release/chardon55/minotp)
Dead simple OTP library for Rust.
License: MIT or Apache-2.0
## Usage
### Installation
Add `minotp` into your project.
```bash
cargo add minotp@1
```Also all hash libraries you want (e.g., SHA1 of [Rust Crypto](https://github.com/RustCrypto)).
```bash
cargo add sha1
```### TOTP (commonly used)
```rust
use minotp::*;
use sha1::Sha1;let secret = b"test";
let totp = Totp::::from_bytes(secret, COMMON_INTERVAL).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`](https://crates.io/crates/data-encoding).
```rust
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::::from_bytes(&secret, COMMON_INTERVAL).unwrap();
let _token = totp.gen_6_str();
// -- snip -- //
```## Found any bug?
~~You must be kidding.~~ Fire an issue right now if you found one!