Make sure TOTP codes can be both Numbers or Strings, fixes #30

This commit is contained in:
Daniel García
2018-05-26 23:04:23 +02:00
parent ca01fa1419
commit 2cf46e1a5f
2 changed files with 16 additions and 6 deletions

View File

@@ -22,7 +22,7 @@ struct PasswordData {
masterPasswordHash: String
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum NumberOrString {
Number(i32),
@@ -36,4 +36,11 @@ impl NumberOrString {
NumberOrString::String(s) => s
}
}
fn to_i32(self) -> Option<i32> {
match self {
NumberOrString::Number(n) => Some(n),
NumberOrString::String(s) => s.parse().ok()
}
}
}