move encrypt and decrypt subcommand impls to functions
This commit is contained in:
parent
138f36f562
commit
37539f7679
1 changed files with 39 additions and 32 deletions
71
src/main.rs
71
src/main.rs
|
@ -230,14 +230,16 @@ fn run() -> anyhow::Result<()> {
|
||||||
return do_subcmd_setup(args, &mut manifest);
|
return do_subcmd_setup(args, &mut manifest);
|
||||||
},
|
},
|
||||||
Some(cli::Subcommands::Import(args)) => {todo!()},
|
Some(cli::Subcommands::Import(args)) => {todo!()},
|
||||||
Some(cli::Subcommands::Encrypt(args)) => {todo!()},
|
Some(cli::Subcommands::Encrypt(args)) => {
|
||||||
Some(cli::Subcommands::Decrypt(args)) => {todo!()},
|
return do_subcmd_encrypt(args, &mut manifest);
|
||||||
|
},
|
||||||
|
Some(cli::Subcommands::Decrypt(args)) => {
|
||||||
|
return do_subcmd_decrypt(args, &mut manifest);
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present("setup") {
|
if let Some(import_matches) = matches.subcommand_matches("import") {
|
||||||
|
|
||||||
} else if let Some(import_matches) = matches.subcommand_matches("import") {
|
|
||||||
for file_path in import_matches.values_of("files").unwrap() {
|
for file_path in import_matches.values_of("files").unwrap() {
|
||||||
match manifest.import_account(file_path.into()) {
|
match manifest.import_account(file_path.into()) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
@ -249,33 +251,6 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest.save()?;
|
|
||||||
return Ok(());
|
|
||||||
} else if matches.is_present("encrypt") {
|
|
||||||
if !manifest.has_passkey() {
|
|
||||||
loop {
|
|
||||||
passkey = rpassword::prompt_password_stdout("Enter encryption passkey: ").ok();
|
|
||||||
let passkey_confirm =
|
|
||||||
rpassword::prompt_password_stdout("Confirm encryption passkey: ").ok();
|
|
||||||
if passkey == passkey_confirm {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
error!("Passkeys do not match, try again.");
|
|
||||||
}
|
|
||||||
manifest.submit_passkey(passkey);
|
|
||||||
}
|
|
||||||
manifest.load_accounts()?;
|
|
||||||
for entry in &mut manifest.entries {
|
|
||||||
entry.encryption = Some(accountmanager::EntryEncryptionParams::generate());
|
|
||||||
}
|
|
||||||
manifest.save()?;
|
|
||||||
return Ok(());
|
|
||||||
} else if matches.is_present("decrypt") {
|
|
||||||
manifest.load_accounts()?;
|
|
||||||
for entry in &mut manifest.entries {
|
|
||||||
entry.encryption = None;
|
|
||||||
}
|
|
||||||
manifest.submit_passkey(None);
|
|
||||||
manifest.save()?;
|
manifest.save()?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -706,3 +681,35 @@ fn do_subcmd_setup(args: cli::ArgsSetup, manifest: &mut accountmanager::Manifest
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_subcmd_encrypt(args: cli::ArgsEncrypt, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> {
|
||||||
|
if !manifest.has_passkey() {
|
||||||
|
let mut passkey;
|
||||||
|
loop {
|
||||||
|
passkey = rpassword::prompt_password_stdout("Enter encryption passkey: ").ok();
|
||||||
|
let passkey_confirm =
|
||||||
|
rpassword::prompt_password_stdout("Confirm encryption passkey: ").ok();
|
||||||
|
if passkey == passkey_confirm {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
error!("Passkeys do not match, try again.");
|
||||||
|
}
|
||||||
|
manifest.submit_passkey(passkey);
|
||||||
|
}
|
||||||
|
manifest.load_accounts()?;
|
||||||
|
for entry in &mut manifest.entries {
|
||||||
|
entry.encryption = Some(accountmanager::EntryEncryptionParams::generate());
|
||||||
|
}
|
||||||
|
manifest.save()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_subcmd_decrypt(args: cli::ArgsDecrypt, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> {
|
||||||
|
manifest.load_accounts()?;
|
||||||
|
for entry in &mut manifest.entries {
|
||||||
|
entry.encryption = None;
|
||||||
|
}
|
||||||
|
manifest.submit_passkey(None);
|
||||||
|
manifest.save()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue