Code reformat.
This commit is contained in:
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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};
|
||||
|
||||
+6
-3
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-4
@@ -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 => {
|
||||
|
||||
+13
-4
@@ -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<Vec<u8>>;
|
||||
|
||||
@@ -77,7 +77,16 @@ impl SKey {
|
||||
}
|
||||
|
||||
pub fn to_b64(&self) -> String {
|
||||
let flat_vec: Vec<u8> = self.otp.iter().map(|v| { let mut v: Vec<u8> = v.clone(); v.reverse(); v }).flatten().collect();
|
||||
let flat_vec: Vec<u8> = self
|
||||
.otp
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let mut v: Vec<u8> = v.clone();
|
||||
v.reverse();
|
||||
v
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
base64::encode(flat_vec).trim_end_matches('=').to_string()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user