diff --git a/src/lk.rs b/src/lk.rs index 6798c42..0f43e6c 100644 --- a/src/lk.rs +++ b/src/lk.rs @@ -10,7 +10,10 @@ pub struct LK { impl LK { pub fn new() -> Self { - Self { db: HashMap::new(), ls: HashMap::new() } + Self { + db: HashMap::new(), + ls: HashMap::new(), + } } pub fn fix_hierarchy(&self) { diff --git a/src/main.rs b/src/main.rs index c15b28a..d0941fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ mod lk; mod parser; mod password; mod repl; -mod structs; mod skey; +mod structs; use rustyline::Editor; use std::{cell::RefCell, rc::Rc}; diff --git a/src/password.rs b/src/password.rs index fb6bc96..22114bd 100644 --- a/src/password.rs +++ b/src/password.rs @@ -1,5 +1,5 @@ -use crate::structs::Mode; use crate::skey::SKey; +use crate::structs::Mode; use chrono::naive::NaiveDate; use std::{cell::RefCell, rc::Rc}; @@ -65,8 +65,11 @@ impl Password { Some(p) => (p.to_owned() + sep + &result).to_string(), None => result, }; - if len > &0_u32 { result.chars().take(*len as usize).collect() } - else { result } + if len > &0_u32 { + result.chars().take(*len as usize).collect() + } else { + result + } } } diff --git a/src/repl.rs b/src/repl.rs index 0bc18d3..23b7fed 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -4,7 +4,7 @@ use std::{cell::RefCell, rc::Rc}; use crate::lk::LK; use crate::parser::command_parser; -use crate::password::{PasswordRef, fix_password_recursion}; +use crate::password::{fix_password_recursion, PasswordRef}; use crate::structs::{Command, LKErr, Radix}; #[derive(Debug)] @@ -80,7 +80,7 @@ impl<'a> LKEval<'a> { None => match self.state.borrow().ls.get(name) { Some(pwd) => Some(pwd.clone()), None => None, - } + }, } } @@ -93,7 +93,8 @@ impl<'a> LKEval<'a> { self.state.borrow_mut().ls.clear(); let mut counter = 1; for pwd in tmp { - let key = Radix::new(counter, 36).unwrap().to_string(); counter += 1; + let key = Radix::new(counter, 36).unwrap().to_string(); + counter += 1; self.state.borrow_mut().ls.insert(key.clone(), pwd.clone()); out.push(format!("{:>3} {}", key, pwd.borrow().to_string())); } @@ -127,7 +128,10 @@ impl<'a> LKEval<'a> { None => out.push("error: password not found".to_string()), }, Command::Rm(name) => match self.get_password(name) { - Some(pwd) => { self.state.borrow_mut().db.remove(&pwd.borrow().name); out.push(format!("removed {}", pwd.borrow().name)); }, + Some(pwd) => { + self.state.borrow_mut().db.remove(&pwd.borrow().name); + out.push(format!("removed {}", pwd.borrow().name)); + } None => out.push("error: password not found".to_string()), }, Command::Help => { diff --git a/src/skey.rs b/src/skey.rs index 727eb04..8f88b3f 100644 --- a/src/skey.rs +++ b/src/skey.rs @@ -1,7 +1,7 @@ -use sha1::{Digest, Sha1}; -use std::vec::Vec; -use std::fmt::Write; use base64; +use sha1::{Digest, Sha1}; +use std::fmt::Write; +use std::vec::Vec; type SKeyOTP = Vec>; @@ -77,7 +77,16 @@ impl SKey { } pub fn to_b64(&self) -> String { - let flat_vec: Vec = self.otp.iter().map(|v| { let mut v: Vec = v.clone(); v.reverse(); v }).flatten().collect(); + let flat_vec: Vec = self + .otp + .iter() + .map(|v| { + let mut v: Vec = v.clone(); + v.reverse(); + v + }) + .flatten() + .collect(); base64::encode(flat_vec).trim_end_matches('=').to_string() } } diff --git a/src/structs.rs b/src/structs.rs index e4a05a8..da6f0bd 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -82,7 +82,7 @@ impl fmt::Display for Radix { let mut used = 0; let negative = x < 0; if negative { - x*=-1; + x *= -1; } let mut x = x as u32; loop {