rusotp
OTP generation and validation library.
- Implements RFC4226 and RFC6238
- Supports alphanumeric OTP generation
- Supports
HmacSha1,HmacSha256, andHmacSha512digests
Note: HmacSha1 support is provided for RFC compliance.
It is recommended to use HmacSha256 or HmacSha512 for better security.
installation
Add rusotp to your Cargo.toml:
[]
= "0.3.4"
HOTP Usage
use ;
const ALGORITHM: Algorithm = SHA256;
const SECRET: &str = "12345678901234567890";
const LENGTH: u8 = 6;
const COUNTER: u64 = 1;
// Generate an OTP
let hotp = HOTPnew.unwrap;
let otp = hotp.generate.unwrap;
println!;
// Verify an OTP
let is_valid = hotp.verify.unwrap;
println!;
// Generate provisioning URI
const ISSUER: &str = "MyService";
const NAME: &str = "user@example.com";
let uri = hotp.provisioning_uri.unwrap;
println!;
TOTP Usage
use ;
const ALGORITHM: Algorithm = SHA256;
const SECRET: &str = "12345678901234567890";
const LENGTH: u8 = 6;
const RADIX: u8 = 10;
const INTERVAL: u8 = 30;
// Generate an OTP
let totp = TOTPnew.unwrap;
let otp = totp.generate.unwrap;
println!;
// Verify an OTP
let is_valid = totp.verify;
println!;
// Generate provisioning URI
const ISSUER: &str = "MyService";
const NAME: &str = "user@example.com";
let uri = totp.provisioning_uri.unwrap;
println!;
Documentation
See the docs.rs/rusotp for more examples and API details.
Contributing
We welcome contributions to the rusotp project! Here are some ways you can help:
- Report Bugs: If you find a bug, please report it by opening an issue on GitHub.
- Suggest Features: If you have an idea for a new feature, please open an issue to discuss it.
- Submit Pull Requests: If you want to contribute code, follow these steps:
- Fork the repository (https://github.com/eendroroy/rusotp/fork)
- Create a new branch (
git checkout -b my-new-feature) - Make your changes and commit them (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Open a Pull Request
Please make sure your contributions adhere to our Code of Conduct.
License
This project is licensed under the GNU AGPL-3.0 License. See the LICENSE file for more details.