mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
chore(vault): provide default for TotpAlgorithm
The default is "None", which will fail any conversion or usage
This commit is contained in:
parent
222a912603
commit
5f7fb22317
1 changed files with 13 additions and 0 deletions
|
|
@ -17,13 +17,22 @@ pub enum TotpAlgorithm {
|
|||
HmacSha1,
|
||||
HmacSha256,
|
||||
HmacSha512,
|
||||
None,
|
||||
}
|
||||
|
||||
impl Default for TotpAlgorithm {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TotpAlgorithm {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
TotpAlgorithm::HmacSha1 => write!(f, "SHA1"),
|
||||
TotpAlgorithm::HmacSha256 => write!(f, "SHA256"),
|
||||
TotpAlgorithm::HmacSha512 => write!(f, "SHA512"),
|
||||
TotpAlgorithm::None => write!(f, "None"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +54,7 @@ impl Into<String> for TotpAlgorithm {
|
|||
TotpAlgorithm::HmacSha1 => "SHA1".to_string(),
|
||||
TotpAlgorithm::HmacSha256 => "SHA256".to_string(),
|
||||
TotpAlgorithm::HmacSha512 => "SHA512".to_string(),
|
||||
TotpAlgorithm::None => "None".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -112,6 +122,9 @@ fn generate_hmac_bytes(unix_timestamp: u64, totp_entry: &TotpEntry) -> Result<Ve
|
|||
let hash: &[u8] = &mac.finalize().into_bytes();
|
||||
computed_hmac.extend_from_slice(hash);
|
||||
}
|
||||
TotpAlgorithm::None => {
|
||||
panic!("cannot generate hmac bytes for None algorithm")
|
||||
}
|
||||
}
|
||||
|
||||
Ok(computed_hmac)
|
||||
|
|
|
|||
Loading…
Reference in a new issue