- Renamed method add_application → create_application,

- Enabled username field of application,
- Made secret hidden while typing,
feature/database-encription
German Lashevich 7 years ago
parent 8a8383cee3
commit a42fe56143

12
Cargo.lock generated

@ -185,6 +185,16 @@ dependencies = [
"redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rpassword"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-hex"
version = "1.0.0"
@ -198,6 +208,7 @@ dependencies = [
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
"oath 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rpassword 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -360,6 +371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rand 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d5f78082e6a6d042862611e9640cf20776185fee506cf6cf67e93c6225cee31"
"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum rpassword 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d127299b02abda51634f14025aec43ae87a7aa7a95202b6a868ec852607d1451"
"checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e"
"checksum serde 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "1c57ab4ec5fa85d08aaf8ed9245899d9bbdd66768945b21113b84d5f595cb6a1"
"checksum serde_derive 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "02c92ea07b6e49b959c1481804ebc9bfd92d3c459f1274c9a9546829e42a66ce"

@ -8,6 +8,7 @@ base32 = "0.3.1"
clap = "^2.29.0"
oath = "0.10.2"
rand = "0.4.1"
rpassword = "2.0.0"
serde = "1.0.24"
serde_derive = "1.0.24"
serde_json = "1.0.8"

@ -2,6 +2,7 @@ extern crate base32;
extern crate clap;
extern crate oath;
extern crate rand;
extern crate rpassword;
extern crate serde_json;
#[macro_use]
@ -32,9 +33,9 @@ impl<DB: Database> RusTOTPony<DB> {
}
}
fn add_application(&mut self, name: &str, secret: &str) -> Result<(), String> {
fn create_application(&mut self, name: &str, username: &str, secret: &str) -> Result<(), String> {
if let Some(secret_bytes) = GenApp::base32_to_bytes(secret) {
let new_app = GenApp::new(name, secret, secret_bytes);
let new_app = GenApp::new(name, username, secret, secret_bytes);
if self.applications.contains_key(name) {
Err(format!("Application with name '{}' already exists!", name))
} else {
@ -185,11 +186,11 @@ struct GenApp {
}
impl GenApp {
fn new(name: &str, secret: &str, secret_bytes: Vec<u8>) -> Self {
fn new(name: &str, username: &str, secret: &str, secret_bytes: Vec<u8>) -> Self {
GenApp {
name: String::from(name),
secret: String::from(secret),
username: String::from(""),
username: String::from(username),
secret_bytes: secret_bytes,
}
}
@ -240,10 +241,8 @@ impl Cli {
let app_name: &str = sub_app
.value_of("APPNAME")
.expect("Couldn't read APPNAME for 'add' command");
let key: &str = sub_app
.value_of("KEY")
.expect("Couldn't read KEY for 'add' command");
self.add_application(app_name, key);
let key: &str = sub_app.value_of("USERNAME").unwrap_or("");
self.create_application(app_name, key);
}
("delete", Some(sub_app)) => {
let app_name: &str = sub_app
@ -291,7 +290,7 @@ impl Cli {
SubCommand::with_name("add")
.about("Adds new generator")
.arg(Arg::with_name("APPNAME").required(true))
.arg(Arg::with_name("KEY").required(true)),
.arg(Arg::with_name("USERNAME")),
)
.subcommand(
SubCommand::with_name("delete")
@ -409,8 +408,9 @@ impl Cli {
println!("{:?}", self.app.get_application(name));
}
fn add_application(&mut self, name: &str, key: &str) {
match self.app.add_application(name, key) {
fn create_application(&mut self, name: &str, username: &str) {
let secret = rpassword::prompt_password_stdout("Enter your secret code: ").unwrap();
match self.app.create_application(name, username, &secret) {
Ok(_) => {
self.app.flush();
println!("New application created: {}", name)

Loading…
Cancel
Save