Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed May 9, 2024
1 parent 5f5dd37 commit 5489b71
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/bin/rbw/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,13 +1948,15 @@ struct TotpParams {
digits: u32,
period: u64,
}

fn decode_totp_secret(secret: &str) -> anyhow::Result<Vec<u8>> {
base32::decode(
base32::Alphabet::RFC4648 { padding: false },
&secret.replace(' ', ""),
)
.ok_or_else(|| anyhow::anyhow!("totp secret was not valid base32"))
}

fn parse_totp_secret(secret: &str) -> anyhow::Result<TotpParams> {
if let Ok(u) = url::Url::parse(secret) {
if u.scheme() != "otpauth" {
Expand Down Expand Up @@ -1990,15 +1992,15 @@ fn parse_totp_secret(secret: &str) -> anyhow::Result<TotpParams> {
anyhow::anyhow!("period parameter in totp url must be a valid integer.")
})?
}
None => 30,
None => totp_lite::DEFAULT_STEP,
}
})
} else {
Ok(TotpParams {
secret: decode_totp_secret(secret)?,
algorithm: String::from("SHA1"),
digits: 6,
period: 30,
period: totp_lite::DEFAULT_STEP,
})
}
}
Expand Down

0 comments on commit 5489b71

Please sign in to comment.