diff --git a/src/argparse.rs b/src/argparse.rs index b4d2f79..525bf81 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -1,16 +1,10 @@ -use crate::date_utils::{ - append_file, argsort, check_dates, offset_and_time, read_file, remove_entry, saved_data_header, - time_date_lef, SavedDate, -}; +use crate::date_utils::{append_file, check_dates, remove_entry, SavedDate}; use crate::view_dates::{get_next_n, grep_by_date, grep_by_description, last_added}; use crate::view_month::{appointment_check, month_len, month_view}; use crate::DATE_FILE_PATH; use chrono::Datelike; -use chrono::{Local, NaiveDate}; +use chrono::NaiveDate; use regex::Regex; -use std::fs; -use std::io; -use std::io::prelude::*; pub fn arg_print(arg_short: &str, arg_long: &str, dtype: &str, msg: &str) { println!("{} | {} <{}>\n {}\n", arg_short, arg_long, dtype, msg) diff --git a/src/date_utils.rs b/src/date_utils.rs index 4931cf7..a04979d 100644 --- a/src/date_utils.rs +++ b/src/date_utils.rs @@ -2,10 +2,8 @@ use crate::encrypt::{gen_key_pwd, get_pwd_file, read_bin, write_bin}; use crate::{PWD_LOC, SALT_LOC}; use chrono::{DateTime, Local, NaiveDateTime, Utc}; use notify_rust::Notification; -use orion::{aead, kdf}; +use orion::aead; use std::fmt; -use std::fs; -use std::io::prelude::*; use std::path::Path; #[derive(Debug)] @@ -155,9 +153,10 @@ pub fn read_file(filepath: &str) -> Vec { } pub fn remove_entry(rm_id: &str, file_path: &str) { + // remove entry by id let file_content = read_file(file_path); let mut removed = Vec::new(); - for (ci, i) in file_content.iter().enumerate() { + for i in file_content.iter() { if i.id.to_string() != rm_id { let acc_line = format!( "{},{},{},{},{}-X-", diff --git a/src/encrypt.rs b/src/encrypt.rs index aa34e72..2ec93fb 100644 --- a/src/encrypt.rs +++ b/src/encrypt.rs @@ -1,9 +1,10 @@ -use orion::{aead, kdf}; +use orion::kdf; use std::fs; use std::fs::File; use std::io::prelude::*; pub fn get_pwd_file(file_path: &str) -> String { + // get password from file let pwd: String = fs::read_to_string(file_path) .expect("Couldn't read pwd file") .trim() @@ -12,6 +13,7 @@ pub fn get_pwd_file(file_path: &str) -> String { } pub fn gen_key_pwd( + // generate salt and password from password string my_pwd: &str, salt: orion::kdf::Salt, ) -> (orion::kdf::Salt, orion::aead::SecretKey) { @@ -23,6 +25,7 @@ pub fn gen_key_pwd( } pub fn write_bin(text: &Vec, file_path: &str) { + // write encrypted text to file let mut old_path: String = file_path.to_owned(); old_path.push_str("_old"); match fs::copy(&file_path, &old_path) { @@ -38,6 +41,7 @@ pub fn write_bin(text: &Vec, file_path: &str) { .expect("Couldn't write content to binary file"); } pub fn read_bin(file_path: &str) -> Vec { + // read binary file let mut file = File::open(file_path).expect("Couldn't open binary file"); let mut buffer = Vec::::new(); file.read_to_end(&mut buffer) diff --git a/src/view_month.rs b/src/view_month.rs index 84f6eef..72243f6 100644 --- a/src/view_month.rs +++ b/src/view_month.rs @@ -1,6 +1,5 @@ use crate::date_utils::SavedDate; use chrono::NaiveDate; -use std::collections::HashMap; pub fn month_len(year: &i32, month: &u32) -> u32 { // get number of days of the month