|
|
|
@ -18,7 +18,7 @@ static USAGE: &'static str = "
|
|
|
|
|
foil
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
foil set [--db=<db>]
|
|
|
|
|
foil set [--namespace=<ns>] [--db=<db>]
|
|
|
|
|
foil get [--namespace=<ns>] [--db=<db>]
|
|
|
|
|
foil list [--db=<db>]
|
|
|
|
|
foil transfer [--db=<db>]
|
|
|
|
@ -120,7 +120,7 @@ fn get(mut db_conn: db::DbHandle, master_key: [u8; 32], namespace: &str) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
|
|
|
|
|
fn set(mut db_conn: db::DbHandle, master_key: [u8; 32], namespace: &str) {
|
|
|
|
|
println!("Adding a site to the database");
|
|
|
|
|
let host: String = Input::with_theme(&ColorfulTheme::default())
|
|
|
|
|
.with_prompt("hostname")
|
|
|
|
@ -130,18 +130,21 @@ fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
|
|
|
|
|
.with_prompt("username")
|
|
|
|
|
.interact()
|
|
|
|
|
.unwrap();
|
|
|
|
|
let encrypted_host: crypt::EncryptedValue = crypt::encrypt_value(&host, master_key);
|
|
|
|
|
let encrypted_username: crypt::EncryptedValue = crypt::encrypt_value(&username, master_key);
|
|
|
|
|
let encrypted_password: crypt::EncryptedValue = {
|
|
|
|
|
let password: String = PasswordInput::with_theme(&ColorfulTheme::default())
|
|
|
|
|
.with_prompt("Site password")
|
|
|
|
|
.with_confirmation("Repeat site password", "Error: the passwords don't match.")
|
|
|
|
|
.interact()
|
|
|
|
|
.unwrap();
|
|
|
|
|
crypt::encrypt_value(&password, master_key)
|
|
|
|
|
};
|
|
|
|
|
db_conn.delete_account_with_host(master_key, &host);
|
|
|
|
|
let _account_id = db_conn.write_account(encrypted_host, encrypted_username, encrypted_password);
|
|
|
|
|
let password: String = PasswordInput::with_theme(&ColorfulTheme::default())
|
|
|
|
|
.with_prompt("Site password")
|
|
|
|
|
.with_confirmation("Repeat site password", "Error: the passwords don't match.")
|
|
|
|
|
.interact()
|
|
|
|
|
.unwrap();
|
|
|
|
|
db_conn.write_note(
|
|
|
|
|
master_key,
|
|
|
|
|
db::Note {
|
|
|
|
|
id: 0,
|
|
|
|
|
namespace: namespace.to_string(),
|
|
|
|
|
category: "account".to_string(),
|
|
|
|
|
title: host,
|
|
|
|
|
value: format!("username: {}\npassword: {}\n", username, password),
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
println!("Successfully added password");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -188,7 +191,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let master_key: [u8; 32] = get_master_key(&mut db_conn);
|
|
|
|
|
|
|
|
|
|
if args.cmd_set {
|
|
|
|
|
set(db_conn, master_key);
|
|
|
|
|
set(db_conn, master_key, &args.flag_namespace);
|
|
|
|
|
} else if args.cmd_get {
|
|
|
|
|
get(db_conn, master_key, &args.flag_namespace);
|
|
|
|
|
} else if args.cmd_list {
|
|
|
|
|