make deepsource happier

This commit is contained in:
Mystikfluu 2023-06-23 15:25:37 +02:00
parent 29f6a59b1f
commit 979c717cc0

View File

@ -29,7 +29,7 @@ struct Saved {
} }
fn get_token() -> Option<String> { fn get_token() -> Option<String> {
let mut token: String = String::new(); let mut token: String = String::default();
//check if file exists //check if file exists
if !std::path::Path::new(&(get_ipass_folder()+"token.ipasst")).exists() { if !std::path::Path::new(&(get_ipass_folder()+"token.ipasst")).exists() {
return None; return None;
@ -211,12 +211,12 @@ pub async fn isync_save() -> bool {
} }
pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) { pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) {
let mut content: String = String::new(); let mut content: String = String::default();
let mut buf = [0u8; 4096]; let mut buf = [0u8; 4096];
loop { loop {
match reader.read(&mut buf[..]) { match reader.read(&mut buf[..]) {
Err(e) => { Err(e) => {
if let std::io::ErrorKind::Interrupted = e.kind() { if e.kind() == std::io::ErrorKind::Interrupted {
continue; continue;
} }
panic!("{}", e); panic!("{}", e);
@ -255,20 +255,20 @@ pub fn import_data<R: Read>(mut reader: brotli::Decompressor<R>) {
} }
pub fn import_file(file_path:&String) -> bool { pub fn import_file(file_path:&String) -> bool {
if std::path::Path::new(file_path).exists() { let file_exists = std::path::Path::new(file_path).exists();
if file_exists {
let reader = brotli::Decompressor::new( let reader = brotli::Decompressor::new(
File::open(file_path).unwrap(), File::open(file_path).unwrap(),
4096, // buffer size 4096, // buffer size
); );
import_data(reader); import_data(reader);
true
} else {
false
} }
file_exists
} }
pub fn export_data() -> Option<Vec<u8>> { pub fn export_data() -> Option<Vec<u8>> {
let mut collected_data = String::new(); let mut collected_data = String::default();
let paths = std::fs::read_dir(get_ipass_folder()).ok()?; let paths = std::fs::read_dir(get_ipass_folder()).ok()?;
for path in paths.flatten() { for path in paths.flatten() {
@ -315,7 +315,7 @@ pub fn export_file(file_path: &String) -> bool {
fn vecu8_to_string(vec: Vec<u8>) -> String { fn vecu8_to_string(vec: Vec<u8>) -> String {
let mut do_print_warning = false; let mut do_print_warning = false;
let mut out: String = String::new(); let mut out: String = String::default();
for ind in vec { for ind in vec {
if let Ok(a) = std::str::from_utf8(&[ind]) { if let Ok(a) = std::str::from_utf8(&[ind]) {
out += a; out += a;
@ -334,7 +334,7 @@ fn vecu8_to_string(vec: Vec<u8>) -> String {
} }
fn encrypt_pass(nonce_arg:String, pass: String,mpw: String) -> String { fn encrypt_pass(nonce_arg:String, pass: String,mpw: String) -> String {
let mut nonce_argument = String::new(); let mut nonce_argument = String::default();
if nonce_arg.len() < 12 { if nonce_arg.len() < 12 {
nonce_argument = nonce_arg.clone() + &" ".repeat(12-nonce_arg.len()); nonce_argument = nonce_arg.clone() + &" ".repeat(12-nonce_arg.len());
} }
@ -362,7 +362,7 @@ fn encrypt_pass(nonce_arg:String, pass: String,mpw: String) -> String {
fn decrypt_pass(nonce_arg:String, pass: Vec<u8>,mpw: String) -> Result<String,String> { fn decrypt_pass(nonce_arg:String, pass: Vec<u8>,mpw: String) -> Result<String,String> {
let mut nonce_argument = String::new(); let mut nonce_argument = String::default();
if nonce_arg.len() < 12 { if nonce_arg.len() < 12 {
nonce_argument = nonce_arg.clone() + &" ".repeat(12-nonce_arg.len()); nonce_argument = nonce_arg.clone() + &" ".repeat(12-nonce_arg.len());
} }
@ -413,7 +413,7 @@ pub fn get_ipass_folder() -> String {
} }
pub fn create_entry(name: &str, pw: String, mpw: String) -> bool { pub fn create_entry(name: &str, pw: String, mpw: String) -> bool {
let mut entry_name = String::new(); let mut entry_name = String::default();
for c in name.chars() { for c in name.chars() {
match c { match c {
':' | '$' | '<' | '>' | '|' | '?' | '*' | '/' | '\\' => {}, ':' | '$' | '<' | '>' | '|' | '?' | '*' | '/' | '\\' => {},
@ -484,7 +484,7 @@ pub fn prompt_answer(toprint: String) -> String {
pub fn prompt_answer_nolower(toprint: String) -> String { pub fn prompt_answer_nolower(toprint: String) -> String {
print!("{toprint}"); print!("{toprint}");
std::io::stdout().flush().unwrap(); std::io::stdout().flush().unwrap();
let mut choice = String::new(); let mut choice = String::default();
std::io::stdin().read_line(&mut choice).expect("Failed to read choice"); std::io::stdin().read_line(&mut choice).expect("Failed to read choice");
return choice.trim().to_string(); return choice.trim().to_string();
@ -517,7 +517,7 @@ pub fn random_password() -> String {
let char_set:Vec<char> = alphabet.chars().collect(); let char_set:Vec<char> = alphabet.chars().collect();
let mut chars_index: Vec<u8> = vec![0;20]; let mut chars_index: Vec<u8> = vec![0;20];
OsRng.fill_bytes(&mut chars_index); OsRng.fill_bytes(&mut chars_index);
let mut chars: String = String::new(); let mut chars: String = String::default();
for index in chars_index { for index in chars_index {
// println!("{} - {} - {}",index,(index as usize)%(alph_len-1),alph_len); // println!("{} - {} - {}",index,(index as usize)%(alph_len-1),alph_len);