Skip to content

Commit

Permalink
Merge pull request #3 from revathskumar/fix/make-case-insensitive
Browse files Browse the repository at this point in the history
Fixes #1: fix showing only 5 chars when OTP starts with 0.
  • Loading branch information
revathskumar authored Jan 5, 2020
2 parents 2a9bd07 + 18e0854 commit 7ad126a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
## 0.3.1

- default will be case insensitive search. Use `grave` key to toggle.

## 0.3.2

- Fixes #1: fix showing only 5 chars when OTP starts with 0.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rofi-totp"
version = "0.3.1"
version = "0.3.2"
authors = ["Revath S Kumar <[email protected]>"]
documentation = "https://github.com/revathskumar/rofi-totp"
homepage = "https://github.com/revathskumar/rofi-totp"
Expand Down
6 changes: 3 additions & 3 deletions src/totp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ extern crate oath;

// use oath::totp;

pub fn generate(secret: &str) -> Result<u64, &'static str> {
pub fn generate(secret: &str) -> Result<String, &'static str> {
let secret_bytes = try!(base32::decode(base32::Alphabet::RFC4648 {padding: false}, &secret.replace(" ", "")).ok_or("invalid base32"));
let code: u64 = oath::totp_raw_now(&secret_bytes, 6, 0, 30, &oath::HashType::SHA1);
Ok(code)
let code: String = oath::totp_raw_now(&secret_bytes, 6, 0, 30, &oath::HashType::SHA1).to_string();
Ok(format!("{:0>6}", code))
}

0 comments on commit 7ad126a

Please sign in to comment.