Merge pull request #237 from Foundation-Devices/display

Implement `Display` instead of `Into<String>`.
This commit is contained in:
bunnie 2022-10-12 11:46:11 -07:00 committed by GitHub
commit 33b72fd6d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 21 deletions

View file

@ -551,14 +551,13 @@ impl ActionManager {
} }
}; };
let alg: String = pw.algorithm.into();
let edit_data = self.modals let edit_data = self.modals
.alert_builder(t!("vault.edit_dialog", xous::LANG)) .alert_builder(t!("vault.edit_dialog", xous::LANG))
.field(Some(pw.name), Some(password_validator)) .field(Some(pw.name), Some(password_validator))
.field(Some(pw.secret), Some(password_validator)) .field(Some(pw.secret), Some(password_validator))
.field(Some(pw.notes), Some(password_validator)) .field(Some(pw.notes), Some(password_validator))
.field(Some(pw.timestep.to_string()), Some(password_validator)) .field(Some(pw.timestep.to_string()), Some(password_validator))
.field(Some(alg), Some(password_validator)) .field(Some(pw.algorithm.to_string()), Some(password_validator))
.field(Some(pw.digits.to_string()), Some(password_validator)) .field(Some(pw.digits.to_string()), Some(password_validator))
.field(Some(if pw.is_hotp {"HOTP".to_string()} else {"TOTP".to_string()}), Some(password_validator)) .field(Some(if pw.is_hotp {"HOTP".to_string()} else {"TOTP".to_string()}), Some(password_validator))
.build().expect("modals error in edit"); .build().expect("modals error in edit");
@ -845,12 +844,11 @@ impl ActionManager {
match record.read_exact(&mut data) { match record.read_exact(&mut data) {
Ok(_len) => { Ok(_len) => {
if let Some(totp) = storage::TotpRecord::try_from(data).ok() { if let Some(totp) = storage::TotpRecord::try_from(data).ok() {
let alg: String = totp.algorithm.into();
let extra = format!("{}:{}:{}:{}:{}", let extra = format!("{}:{}:{}:{}:{}",
totp.secret, totp.secret,
totp.digits, totp.digits,
totp.timestep, totp.timestep,
alg, totp.algorithm,
if totp.is_hotp {"HOTP"} else {"TOTP"} if totp.is_hotp {"HOTP"} else {"TOTP"}
); );
let desc = format!("{}", totp.name); let desc = format!("{}", totp.name);

View file

@ -427,7 +427,6 @@ impl StorageContent for TotpRecord {
Ok(()) Ok(())
} }
fn to_vec(&self) -> Vec<u8> { fn to_vec(&self) -> Vec<u8> {
let ta: String = self.algorithm.into();
format!( format!(
"{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n", "{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n",
"version", "version",
@ -437,7 +436,7 @@ impl StorageContent for TotpRecord {
"name", "name",
self.name, self.name,
"algorithm", "algorithm",
ta, self.algorithm,
"notes", "notes",
self.notes, self.notes,
"digits", "digits",
@ -551,7 +550,6 @@ impl TryFrom<Vec<u8>> for TotpRecord {
impl From<TotpRecord> for Vec<u8> { impl From<TotpRecord> for Vec<u8> {
fn from(tr: TotpRecord) -> Self { fn from(tr: TotpRecord) -> Self {
let ta: String = tr.algorithm.into();
format!( format!(
"{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n", "{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}\n",
"version", "version",
@ -561,7 +559,7 @@ impl From<TotpRecord> for Vec<u8> {
"name", "name",
tr.name, tr.name,
"algorithm", "algorithm",
ta, tr.algorithm,
"notes", "notes",
tr.notes, tr.notes,
"digits", "digits",

View file

@ -48,13 +48,13 @@ impl TryFrom<&str> for TotpAlgorithm {
} }
} }
} }
impl Into<String> for TotpAlgorithm { impl core::fmt::Display for TotpAlgorithm {
fn into(self) -> String { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self { match self {
TotpAlgorithm::HmacSha1 => "SHA1".to_string(), TotpAlgorithm::HmacSha1 => write!(f, "SHA1"),
TotpAlgorithm::HmacSha256 => "SHA256".to_string(), TotpAlgorithm::HmacSha256 => write!(f, "SHA256"),
TotpAlgorithm::HmacSha512 => "SHA512".to_string(), TotpAlgorithm::HmacSha512 => write!(f, "SHA512"),
TotpAlgorithm::None => "None".to_string(), TotpAlgorithm::None => write!(f, "None"),
} }
} }
} }

View file

@ -836,12 +836,11 @@ impl VaultUx {
} }
} }
// update the "extra" field, because the timestep field has been altered // update the "extra" field, because the timestep field has been altered
let alg: String = hotp_rec.algorithm.into();
self.filtered_list[self.selection_index].extra = format!("{}:{}:{}:{}:{}", self.filtered_list[self.selection_index].extra = format!("{}:{}:{}:{}:{}",
hotp_rec.secret, hotp_rec.secret,
hotp_rec.digits, hotp_rec.digits,
hotp_rec.timestep, hotp_rec.timestep,
alg, hotp_rec.algorithm,
if hotp_rec.is_hotp {"HOTP"} else {"TOTP"} if hotp_rec.is_hotp {"HOTP"} else {"TOTP"}
); );
self.filtered_list[self.selection_index].dirty = true; self.filtered_list[self.selection_index].dirty = true;

View file

@ -12,13 +12,13 @@ impl ProcessKey {
} }
} }
impl Into<String> for ProcessKey { impl core::fmt::Display for ProcessKey {
fn into(self) -> String { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut out = String::new();
for i in self.0 { for i in self.0 {
out.push_str(&format!("{:02x}", i)); write!(f, "{:02x}", i)?;
} }
out
Ok(())
} }
} }