From 77aeba49b1ba9c85f1129844f2f41ba028f6063b Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Tue, 27 Dec 2022 01:48:20 +0100 Subject: [PATCH] Init ig Co-authored-by: Alpisc --- .gitignore | 1 + Cargo.lock | 41 ++++++++++++++++ Cargo.toml | 9 ++++ src/main.rs | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..98c1d85 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,41 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "home" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +dependencies = [ + "winapi", +] + +[[package]] +name = "ipass" +version = "0.1.0" +dependencies = [ + "home", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2cb6d31 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ipass" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +home = "0.5.4" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1e2d7f5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,131 @@ +use std::collections::HashMap; +use home::home_dir; +use std::fs; + +fn get_args() -> Vec { + std::env::args().collect() // [0] = file path; [n>0] = argument +} + +fn get_home_folder_str() -> String { + match home::home_dir() { + Some(path) => { + let p = path.to_str(); + match p { + Some(pa) => return pa.to_owned(), + None => return "".to_owned(), + } + }, + None => return "".to_owned(), + } +} + +fn get_ipass_folder() -> String { + let path = get_home_folder_str()+"/.IPass/"; + fs::create_dir_all(&path).unwrap(); + return path; +} + +fn main() { + let args = get_args(); + + if args.len()<2 { + help_message() + } + + let mode: &str = &args[1].trim().to_lowercase().to_owned(); + + match mode { + "list" => list(), + "add" => add(), + "get" => get(), + "edit" => edit(), + "remove" => remove(), + _ => help_message(), + } + + + +} + +fn help_message() { + + let version = "0.0.1"; + println!("IPass v{}\n", version); + + let args = get_args(); + + let mut help_messages:HashMap = HashMap::new(); + help_messages.insert( + "list".to_string(), + "returns a list of all saved entries".to_string(), + ); + help_messages.insert( + "add".to_string(), + "creates a new entry taking a [name] and an optional {password} ".to_string(), + ); + help_messages.insert( + "get".to_string(), + "returns a specific entry, selected by the provided [name]".to_string(), + ); + help_messages.insert( + "help".to_string(), + "tells you this message, takes an optional {command name}".to_string(), + ); + help_messages.insert( + "edit".to_string(), + "lets you edit an existing entry, given the name and the new password".to_string(), + ); + help_messages.insert( + "remove".to_string(), + "removes an existing entry".to_string(), + ); + + if args.len()<3 { + print!("The possible commands are: "); + for i in help_messages.keys() { + print!("\"{i}\" "); + } + return; + } + + + + println!("{} {}", &args[2], &help_messages[&args[2]]) +} + +fn get_pw() -> String { + let mut output: String = String::new(); + std::io::stdin().read_line(&mut output).expect("Failed to read line"); + return output.replace("\n", "").replace("\r",""); +} + +fn list() { + todo!("List websites/names"); +} + +fn add() { + todo!("Add password") + // create_entry(args[3],encrypt_pass(args[4])); +} + +fn get() { + todo!("Get password") +} + +fn edit() { + todo!("Edit entry") +} + +fn remove() { + todo!("Removes entry") +} + +fn encrypt_pass(pass: &str) -> &str { + return pass; +} + +/* +prog.exe list -> all saved entries +prog.exe add [Name] \n **in stars** {password} +prog.exe get [Name] +*/ \ No newline at end of file