Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,258 changes: 664 additions & 594 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ arboard = "3.4.0"
glob = "0.3.1"
gpgme = "0.11.0"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
git2 = "0.19.0"
git2 = "0.20.0"
rand = "0.8.5"
whoami = "1.4.1"
toml = "0.8.10"
Expand All @@ -22,12 +22,11 @@ hex = "0.4.3"
totp-rs = { version = "5.5.1", features = ["otpauth"] }
sequoia-openpgp = "1.21.0"
anyhow = "1.0.80"
sequoia-ipc = "0.35.0"
sequoia-gpg-agent = "0.4.0"
zeroize = { version = "1.8.0", features = ["zeroize_derive", "alloc"] }

[dependencies.config]
version = "0.11.0"
version = "0.15.4"
default-features = false
features = ["toml"]

Expand Down
3 changes: 1 addition & 2 deletions cursive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ locale_config = "0.3.0"
unic-langid = "0.9.4"
gettext = "0.4.0"
lazy_static = "1.4.0"
toml = "0.8.10"
terminal_size = "0.3.0"
hex = "0.4.3"
zeroize = { version = "1.7.0", features = ["zeroize_derive", "alloc"] }

[dependencies.config]
version = "0.11.0"
version = "0.15.5"
default-features = false
features = ["toml"]

Expand Down
2 changes: 1 addition & 1 deletion cursive/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn set_clipboard(content: &String) -> Result<()> {
Ok(CLIPBOARD.lock().unwrap().set_text(content)?)
}

pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option<std::sync::Arc<String>> {
pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option<Arc<String>> {
let mut password = None;
s.call_on_name(input_name, |e: &mut EditView| {
password = Some(e.get_content());
Expand Down
85 changes: 37 additions & 48 deletions cursive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn up(ui: &mut Cursive) {
}

fn page_down(ui: &mut Cursive) {
let rows = screen_height(&ui) - 7;
let rows = screen_height(ui) - 7;
ui.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.select_down(rows);
});
Expand All @@ -119,7 +119,7 @@ fn page_down(ui: &mut Cursive) {
}

fn page_up(ui: &mut Cursive) {
let rows = screen_height(&ui) - 7;
let rows = screen_height(ui) - 7;
ui.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.select_up(rows);
});
Expand All @@ -140,7 +140,7 @@ fn copy(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret: String = sel.unwrap().secret(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand Down Expand Up @@ -168,7 +168,7 @@ fn copy_first_line(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret = sel.unwrap().password(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand Down Expand Up @@ -198,7 +198,7 @@ fn copy_mfa(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret = sel.unwrap().mfa(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand All @@ -224,7 +224,7 @@ fn copy_name(ui: &mut Cursive) {
}
let sel = sel.unwrap();

if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let name = sel.name.split('/').next_back();
helpers::set_clipboard(&name.unwrap_or("").to_string())?;
Ok(())
Expand Down Expand Up @@ -281,8 +281,8 @@ fn delete(ui: &mut Cursive, store: PasswordStoreType) {
));
}

fn get_selected_password_entry(ui: &mut Cursive) -> Option<ripasso::pass::PasswordEntry> {
let password_entry_option: Option<Option<Arc<ripasso::pass::PasswordEntry>>> = ui
fn get_selected_password_entry(ui: &mut Cursive) -> Option<pass::PasswordEntry> {
let password_entry_option: Option<Option<Arc<pass::PasswordEntry>>> = ui
.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.selection()
});
Expand Down Expand Up @@ -716,12 +716,12 @@ fn create(ui: &mut Cursive, store: PasswordStoreType) {

fn delete_recipient(ui: &mut Cursive, store: PasswordStoreType) -> Result<()> {
let mut l = ui
.find_name::<SelectView<Option<(PathBuf, pass::Recipient)>>>("recipients")
.find_name::<SelectView<Option<(PathBuf, Recipient)>>>("recipients")
.unwrap();
let sel = l.selection();

if sel.is_none() || sel.as_ref().unwrap().is_none() {
return Err(crate::pass::Error::Generic("Selection is empty"));
return Err(pass::Error::Generic("Selection is empty"));
}

let binding = sel.unwrap();
Expand Down Expand Up @@ -795,9 +795,7 @@ fn add_recipient(ui: &mut Cursive, store: PasswordStoreType, config_path: &Path)
}

let mut recipients_view = ui
.find_name::<SelectView<Option<(PathBuf, pass::Recipient)>>>(
"recipients",
)
.find_name::<SelectView<Option<(PathBuf, Recipient)>>>("recipients")
.unwrap();
recipients_view.add_item(
render_recipient_label(&recipient, max_width_key, max_width_name),
Expand Down Expand Up @@ -870,7 +868,7 @@ fn add_recipient_dialog(ui: &mut Cursive, store: PasswordStoreType, config_path:
}

fn render_recipient_label(
recipient: &pass::Recipient,
recipient: &Recipient,
max_width_key: usize,
max_width_name: usize,
) -> String {
Expand Down Expand Up @@ -929,7 +927,7 @@ fn view_recipients(ui: &mut Cursive, store: PasswordStoreType, config_path: &Pat
helpers::errorbox(ui, &err);
return Ok(());
}
let sub_dirs = sub_dirs.unwrap();
let sub_dirs = sub_dirs?;

match sub_dirs.len().cmp(&1) {
std::cmp::Ordering::Greater => {
Expand All @@ -942,7 +940,7 @@ fn view_recipients(ui: &mut Cursive, store: PasswordStoreType, config_path: &Pat
return Ok(());
}

path_to_recipients.insert(dir.clone(), recipients_res.unwrap());
path_to_recipients.insert(dir.clone(), recipients_res?);
}

view_recipients_for_many_dirs(ui, store, path_to_recipients, config_path);
Expand Down Expand Up @@ -971,7 +969,7 @@ fn view_recipients_for_many_dirs(
path_to_recipients: HashMap<PathBuf, Vec<Recipient>>,
config_path: &Path,
) {
let mut recipients_view = SelectView::<Option<(PathBuf, pass::Recipient)>>::new()
let mut recipients_view = SelectView::<Option<(PathBuf, Recipient)>>::new()
.h_align(cursive::align::HAlign::Left)
.with_name("recipients");

Expand Down Expand Up @@ -1048,9 +1046,9 @@ fn view_recipients_for_dir(
helpers::errorbox(ui, &err);
return Ok(());
}
let recipients = recipients_res.unwrap();
let recipients = recipients_res?;

let mut recipients_view = SelectView::<Option<(PathBuf, pass::Recipient)>>::new()
let mut recipients_view = SelectView::<Option<(PathBuf, Recipient)>>::new()
.h_align(cursive::align::HAlign::Left)
.with_name("recipients");

Expand Down Expand Up @@ -1108,10 +1106,7 @@ fn create_label(p: &pass::PasswordEntry, col: usize) -> String {
let committed_by = p.committed_by.clone();
let updated = p.updated;
let name = substr(
&match committed_by {
Some(d) => d,
None => CATALOG.gettext("n/a").to_string(),
},
&committed_by.unwrap_or_else(|| CATALOG.gettext("n/a").to_string()),
0,
15,
);
Expand Down Expand Up @@ -1377,21 +1372,17 @@ fn get_stores(config: &config::Config, home: &Option<PathBuf>) -> Result<Vec<Pas
let stores: HashMap<String, config::Value> = stores;

for store_name in stores.keys() {
let store: HashMap<String, config::Value> = stores
.get(store_name)
.unwrap()
.clone()
.into_table()
.unwrap();
let store: HashMap<String, config::Value> =
stores.get(store_name).unwrap().clone().into_table()?;

let password_store_dir_opt = store.get("path");
let valid_signing_keys_opt = store.get("valid_signing_keys");

if let Some(store_dir) = password_store_dir_opt {
let password_store_dir = Some(PathBuf::from(store_dir.clone().into_str()?));
let password_store_dir = Some(PathBuf::from(store_dir.clone().into_string()?));

let valid_signing_keys = match valid_signing_keys_opt {
Some(k) => match k.clone().into_str() {
Some(k) => match k.clone().into_string() {
Err(_) => None,
Ok(key) => {
if key == "-1" {
Expand All @@ -1404,22 +1395,22 @@ fn get_stores(config: &config::Config, home: &Option<PathBuf>) -> Result<Vec<Pas
None => None,
};
let style_path_opt = match store.get("style_path") {
Some(path) => match path.clone().into_str() {
Some(path) => match path.clone().into_string() {
Ok(p) => Some(PathBuf::from(p)),
Err(_err) => None,
},
None => None,
};

let pgp_impl = match store.get("pgp") {
Some(pgp_str) => CryptoImpl::try_from(pgp_str.clone().into_str()?.as_str()),
Some(pgp_str) => CryptoImpl::try_from(pgp_str.clone().into_string()?.as_str()),
None => Ok(CryptoImpl::GpgMe),
}?;

let own_fingerprint = store.get("own_fingerprint");
let own_fingerprint = match own_fingerprint {
None => None,
Some(k) => match k.clone().into_str() {
Some(k) => match k.clone().into_string() {
Err(_) => None,
Ok(key) => match <[u8; 20]>::from_hex(key) {
Err(_) => None,
Expand Down Expand Up @@ -1477,11 +1468,11 @@ fn validate_stores_config(settings: &config::Config, home: &Option<PathBuf>) ->
let password_store_dir_opt = store.get("path");

if let Some(p) = password_store_dir_opt {
let p_path = PathBuf::from(p.clone().into_str().unwrap());
let p_path = PathBuf::from(p.clone().into_string().unwrap());
let gpg_id = p_path.clone().join(".gpg-id");

if !p_path.exists() || !gpg_id.exists() {
incomplete_stores.push(PathBuf::from(p.clone().into_str().unwrap()));
incomplete_stores.push(PathBuf::from(p.clone().into_string().unwrap()));
}
}
}
Expand Down Expand Up @@ -1520,8 +1511,7 @@ fn save_edit_config(

let e_k = if e_k_bool {
let mut recipients: Vec<Recipient> = vec![];
for (i, r) in all_recipients_from_stores(stores.clone())
.unwrap()
for (i, r) in all_recipients_from_stores(stores.clone())?
.iter()
.enumerate()
{
Expand Down Expand Up @@ -1563,7 +1553,7 @@ fn save_edit_config(
helpers::errorbox(ui, &err);
return Ok(());
}
let new_store = new_store.unwrap();
let new_store = new_store?;

let l = ui.find_name::<SelectView<String>>("stores").unwrap();

Expand Down Expand Up @@ -2040,7 +2030,7 @@ fn main() -> Result<()> {
2 => {
if args[1] == "-h" || args[1] == "--help" {
help();
std::process::exit(0);
process::exit(0);
} else {
eprintln!(
"{}",
Expand Down Expand Up @@ -2092,7 +2082,7 @@ fn main() -> Result<()> {
eprintln!("Error {err}");
process::exit(1);
}
let (config, config_file_location) = config_res.unwrap();
let (config, config_file_location) = config_res?;

for path in validate_stores_config(&config, &home) {
wizard::show_init_menu(&Some(path), &home);
Expand All @@ -2105,8 +2095,7 @@ fn main() -> Result<()> {
}

let stores: StoreListType = Arc::new(Mutex::new(
stores
.unwrap()
stores?
.into_iter()
.map(|s| Arc::new(Mutex::new(s)))
.collect(),
Expand Down Expand Up @@ -2175,8 +2164,8 @@ fn main() -> Result<()> {
// Movement
ui.add_global_callback(Event::CtrlChar('n'), down);
ui.add_global_callback(Event::CtrlChar('p'), up);
ui.add_global_callback(Event::Key(cursive::event::Key::PageDown), page_down);
ui.add_global_callback(Event::Key(cursive::event::Key::PageUp), page_up);
ui.add_global_callback(Event::Key(Key::PageDown), page_down);
ui.add_global_callback(Event::Key(Key::PageUp), page_up);

// View list of persons that have access
ui.add_global_callback(Event::CtrlChar('v'), {
Expand Down Expand Up @@ -2224,14 +2213,14 @@ fn main() -> Result<()> {
do_git_push(ui, store.clone());
}
});
ui.add_global_callback(Event::Key(cursive::event::Key::Ins), {
ui.add_global_callback(Event::Key(Key::Ins), {
let store = store.clone();
move |ui: &mut Cursive| {
create(ui, store.clone());
}
});

ui.add_global_callback(Event::Key(cursive::event::Key::Esc), |s| s.quit());
ui.add_global_callback(Event::Key(Key::Esc), |s| s.quit());

if let Err(err) = ui.load_toml(&get_style(&store.lock()?.lock()?.get_style_file())) {
eprintln!("Error {err:?}");
Expand All @@ -2240,7 +2229,7 @@ fn main() -> Result<()> {
let search_box = EditView::new()
.on_edit({
let store = store.clone();
move |ui: &mut cursive::Cursive, query, _| {
move |ui: &mut Cursive, query, _| {
do_search(&store, ui, query);
}
})
Expand Down
8 changes: 4 additions & 4 deletions cursive/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn is_checkbox_checked_false() {
let mut siv = cursive::default();
siv.add_layer(Checkbox::new().with_name("unit_test"));

assert_eq!(false, is_checkbox_checked(&mut siv, "unit_test"));
assert!(!is_checkbox_checked(&mut siv, "unit_test"));
}

#[test]
Expand All @@ -39,7 +39,7 @@ fn is_checkbox_checked_true() {
c_b.set_checked(true);
siv.add_layer(c_b.with_name("unit_test"));

assert_eq!(true, is_checkbox_checked(&mut siv, "unit_test"));
assert!(is_checkbox_checked(&mut siv, "unit_test"));
}

#[test]
Expand All @@ -56,7 +56,7 @@ fn is_radio_button_selected_false() {

siv.add_layer(ll);

assert_eq!(false, is_radio_button_selected(&mut siv, "button1_name"));
assert!(!is_radio_button_selected(&mut siv, "button1_name"));
}

#[test]
Expand All @@ -79,5 +79,5 @@ fn is_radio_button_selected_true() {
e.select();
});

assert_eq!(true, is_radio_button_selected(&mut siv, "button2_name"));
assert!(is_radio_button_selected(&mut siv, "button2_name"));
}
4 changes: 2 additions & 2 deletions cursive/src/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn do_delete_normal() {
let mut siv = cursive::default();

let td = tempdir().unwrap();
std::fs::create_dir(&td.path().join(".password-store")).unwrap();
std::fs::create_dir(td.path().join(".password-store")).unwrap();
std::fs::write(
&td.path().join(".password-store").join("file.gpg"),
td.path().join(".password-store").join("file.gpg"),
"pgp-data",
)
.unwrap();
Expand Down
Loading
Loading