diff --git a/hel/Cargo.toml b/hel/Cargo.toml index 76ae296..b6f2f7a 100644 --- a/hel/Cargo.toml +++ b/hel/Cargo.toml @@ -19,7 +19,6 @@ thiserror = "1.0.37" anyerror = "0.1.7" sha1 = "0.10.5" base64 = "0.20.0" -rpassword = "7.2.0" shlex = "1.1.0" shellexpand = "3.0.0" scopeguard = "1.1.0" @@ -29,3 +28,4 @@ chrono = "0.4.23" rand = "0.8.5" home = "0.5.4" rustyline = "10.0.0" +rpassword = "7.2.0" diff --git a/hel/src/commands.rs b/hel/src/commands.rs index 0fe7362..86e6243 100644 --- a/hel/src/commands.rs +++ b/hel/src/commands.rs @@ -1,5 +1,4 @@ use regex::Regex; -use rpassword::prompt_password; use sha1::{Digest, Sha1}; use std::cmp::min; use std::collections::{HashMap, HashSet}; @@ -13,6 +12,7 @@ use crate::password::{Name, Password, PasswordRef}; use crate::repl::LKEval; use crate::structs::{LKOut, Radix, CORRECT_FILE, DUMP_FILE}; use crate::utils::{call_cmd_with_input, get_cmd_args_from_command, get_copy_command_from_env, rnd}; +use crate::utils::editor::password; impl<'a> LKEval<'a> { pub fn get_password(&self, name: &String) -> Option { @@ -251,7 +251,7 @@ impl<'a> LKEval<'a> { match command_parser::script(&script) { Ok(cmd_list) => { for cmd in cmd_list { - let print = LKEval::new(cmd, self.state.clone(), prompt_password).eval(); + let print = LKEval::new(cmd, self.state.clone(), password).eval(); print.out.copy(&out); if print.quit { return true; } } diff --git a/hel/src/repl.rs b/hel/src/repl.rs index a105a36..b23acbc 100644 --- a/hel/src/repl.rs +++ b/hel/src/repl.rs @@ -1,10 +1,9 @@ -use rpassword::prompt_password; use std::{cell::RefCell, rc::Rc}; use crate::lk::LK; use crate::parser::command_parser; use crate::structs::{Command, LKErr, LKOut, HISTORY_FILE}; -use crate::utils::editor::Editor; +use crate::utils::editor::{ Editor, password }; #[derive(Debug)] pub struct LKRead { @@ -36,7 +35,7 @@ impl LKRead { prompt, state, cmd: "".to_string(), - read_password: prompt_password, + read_password: password, } } @@ -153,8 +152,8 @@ mod tests { use super::*; use crate::password::Password; use crate::structs::Mode; - use chrono::naive::NaiveDate; use std::collections::HashMap; + use crate::utils::date::Date; impl<'a> LKEval<'a> { pub fn news(cmd: Command<'a>, state: Rc>) -> Self { @@ -181,7 +180,7 @@ mod tests { length: None, mode: Mode::Regular, seq: 99, - date: NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(), + date: Date::new(2022, 12, 30), comment: Some("comment".to_string()), parent: None, })); @@ -208,7 +207,7 @@ mod tests { length: None, mode: Mode::Regular, seq: 99, - date: NaiveDate::from_ymd_opt(2022, 12, 31).unwrap(), + date: Date::new(2022, 12, 31), comment: Some("bli blup".to_string()), parent: None, })); @@ -252,7 +251,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(), + Date::new(2022, 12, 30), None, ))); let t2 = Rc::new(RefCell::new(Password::new( @@ -261,7 +260,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(), + Date::new(2022, 12, 30), None, ))); let t3 = Rc::new(RefCell::new(Password::new( @@ -270,7 +269,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(), + Date::new(2022, 12, 30), None, ))); assert_eq!( diff --git a/hel/src/structs.rs b/hel/src/structs.rs index 2a7b022..53ac732 100644 --- a/hel/src/structs.rs +++ b/hel/src/structs.rs @@ -1,5 +1,4 @@ use crate::password::{Comment, Name, PasswordRef}; -use rpassword::prompt_password; use std::fmt; use std::path::Path; use std::{cell::RefCell, rc::Rc}; @@ -8,7 +7,7 @@ use crate::lk::LK; use crate::parser::command_parser; use crate::repl::{LKEval, LKRead}; use crate::utils::home; -use crate::utils::editor::Editor; +use crate::utils::editor::{ Editor, password }; lazy_static! { pub static ref HISTORY_FILE: Box = { @@ -270,11 +269,11 @@ pub fn init() -> Option { Ok(script) => match command_parser::script(&script) { Ok(cmd_list) => { for cmd in cmd_list { - if !LKEval::new(cmd, lk.clone(), prompt_password).eval().print() { return None; } + if !LKEval::new(cmd, lk.clone(), password).eval().print() { return None; } } } Err(err) => { - LKEval::new(Command::Error(LKErr::ParseError(err)), lk.clone(), prompt_password).eval().print(); + LKEval::new(Command::Error(LKErr::ParseError(err)), lk.clone(), password).eval().print(); } }, Err(err) if err.kind() == std::io::ErrorKind::NotFound => (), @@ -284,7 +283,7 @@ pub fn init() -> Option { format!("Failed to read init file {:?}: {}", INIT_FILE.to_str(), err).as_str(), )), lk.clone(), - prompt_password, + password, ) .eval() .print(); @@ -297,7 +296,7 @@ pub fn init() -> Option { mod tests { use super::*; use crate::password::Password; - use chrono::naive::NaiveDate; + use crate::utils::date::Date; use std::io::{BufWriter, Write}; use std::os::unix::fs::PermissionsExt; @@ -358,7 +357,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(), + Date::new(2022, 10, 10), None, ))); let t2 = Rc::new(RefCell::new(Password::new( @@ -367,7 +366,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(), + Date::new(2022, 10, 10), Some("test".to_string()), ))); t2.borrow_mut().parent = Some(t1.clone()); @@ -377,7 +376,7 @@ mod tests { None, Mode::Regular, 99, - NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(), + Date::new(2022, 10, 10), Some("aoeu".to_string()), ))); t3.borrow_mut().parent = Some(t2.clone()); @@ -385,7 +384,7 @@ mod tests { assert_eq!(*lkread.state.borrow().db.get("t2").unwrap().borrow(), *t2.borrow()); assert_eq!(*lkread.state.borrow().db.get("t3").unwrap().borrow(), *t3.borrow()); - LKEval::new(command_parser::cmd("dump").unwrap(), lkread.state.clone(), prompt_password) + LKEval::new(command_parser::cmd("dump").unwrap(), lkread.state.clone(), password) .eval() .print(); assert_eq!( diff --git a/hel/src/utils.rs b/hel/src/utils.rs index 55583f4..eb2d1a8 100644 --- a/hel/src/utils.rs +++ b/hel/src/utils.rs @@ -10,7 +10,7 @@ pub mod date { use chrono::naive::NaiveDate; use chrono::Local; - #[derive(PartialEq, Debug, Clone)] + #[derive(PartialEq, Debug, Clone, Copy)] pub struct Date { date: NaiveDate } @@ -107,6 +107,10 @@ pub mod editor { } } } + + pub fn password(prompt: impl ToString) -> std::io::Result { + rpassword::prompt_password(prompt) + } } pub fn call_cmd_with_input(cmd: &str, args: &Vec, input: &str) -> io::Result {