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
335 changes: 175 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sequoia-openpgp = "2"
anyhow = "1"
sequoia-gpg-agent = "0.6"
zeroize = { version = "1", features = ["zeroize_derive", "alloc"] }
thiserror = "2"

[dependencies.config]
version = "0.15"
Expand Down
30 changes: 14 additions & 16 deletions cursive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::{
collections::HashMap,
path::{Path, PathBuf},
process,
sync::{Arc, LazyLock, Mutex, MutexGuard},
thread, time,
};

use config::Config;
use cursive::{
Cursive, CursiveExt,
Expand All @@ -28,31 +36,21 @@ use cursive::{
};
use pass::Result;
use ripasso::{
crypto::CryptoImpl,
crypto::{CryptoImpl, Fingerprint},
git::{pull, push},
pass,
pass::{
OwnerTrustLevel, PasswordStore, Recipient, SignatureStatus, all_recipients_from_stores,
},
passphrase_generator::passphrase_generator,
password_generator::password_generator,
};
use std::sync::{LazyLock, MutexGuard};
use std::{
collections::HashMap,
path::{Path, PathBuf},
process,
sync::{Arc, Mutex},
thread, time,
password_generator::{PasswordGenerationCategory, password_generator},
};
use unic_langid::LanguageIdentifier;
use zeroize::Zeroize;

use crate::helpers::{
get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths,
};
use ripasso::crypto::Fingerprint;
use ripasso::password_generator::PasswordGenerationCategory;
use zeroize::Zeroize;

mod helpers;
mod wizard;
Expand Down Expand Up @@ -864,7 +862,7 @@ fn delete_recipient(ui: &mut Cursive, store: &PasswordStoreType) -> Result<()> {
let sel = l.selection();

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

let binding = sel.unwrap();
Expand Down Expand Up @@ -914,7 +912,7 @@ fn add_recipient(ui: &mut Cursive, store: &PasswordStoreType, config_path: &Path
Err(err) => helpers::errorbox(ui, &err),
Ok(recipient) => {
if recipient.trust_level != OwnerTrustLevel::Ultimate {
helpers::errorbox(ui, &pass::Error::Generic(CATALOG.gettext("Can't import team member due to that the GPG trust relationship level isn't Ultimate")));
helpers::errorbox(ui, &pass::Error::from(CATALOG.gettext("Can't import team member due to that the GPG trust relationship level isn't Ultimate")));
return Ok(());
}

Expand Down Expand Up @@ -1082,7 +1080,7 @@ fn view_recipients(ui: &mut Cursive, store: &PasswordStoreType, config_path: &Pa
do_view_recipients_for_dir(ui, store, &sub_dirs[0], config_path);
}
std::cmp::Ordering::Less => {
helpers::errorbox(ui, &pass::Error::Generic("no subdirectories found"));
helpers::errorbox(ui, &pass::Error::from("no subdirectories found"));
}
}

Expand Down
7 changes: 4 additions & 3 deletions cursive/src/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::sync::Arc;

use crate::helpers::{
get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths,
};
use cursive::{
view::Nameable,
views::{Checkbox, EditView, LinearLayout, RadioButton, RadioGroup},
Expand All @@ -13,6 +10,10 @@ use ripasso::{
pass::{Comment, KeyRingStatus, OwnerTrustLevel, Recipient},
};

use crate::helpers::{
get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths,
};

#[test]
fn test_get_value_from_input() {
let mut siv = cursive::default();
Expand Down
15 changes: 8 additions & 7 deletions gtk/src/window/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
mod imp;

use crate::{collection_object::CollectionObject, password_object::PasswordObject};
use std::{
collections::HashMap,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};

use adw::{ActionRow, NavigationDirection, prelude::*, subclass::prelude::*};
use glib::{Object, clone};
use gtk::{
AboutDialog, CustomFilter, Dialog, DialogFlags, Entry, FilterListModel, Label, ListBox,
ListBoxRow, NoSelection, ResponseType, SelectionMode, gio, glib, glib::BindingFlags, pango,
};
use ripasso::{crypto::CryptoImpl, pass::PasswordStore};
use std::path::Path;
use std::{
collections::HashMap,
path::PathBuf,
sync::{Arc, Mutex},
};

use crate::{collection_object::CollectionObject, password_object::PasswordObject};

glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
Expand Down
26 changes: 13 additions & 13 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TryFrom<&str> for CryptoImpl {
match value {
"gpg" => Ok(Self::GpgMe),
"sequoia" => Ok(Self::Sequoia),
_ => Err(Error::Generic(
_ => Err(Error::from(
"unknown pgp implementation value, valid values are 'gpg' and 'sequoia'",
)),
}
Expand Down Expand Up @@ -147,7 +147,7 @@ impl TryFrom<&[u8]> for Fingerprint {
32 => Ok(Fingerprint::V6(
b.try_into().expect("slice with incorrect length"),
)),
_ => Err(Error::Generic("slice isn't 20 or 32 bytes")),
_ => Err(Error::from("slice isn't 20 or 32 bytes")),
}
}
}
Expand All @@ -166,7 +166,7 @@ impl TryFrom<&str> for Fingerprint {
} else if key.len() == 66 {
Ok(Fingerprint::from(<[u8; 32]>::from_hex(&key[2..])?))
} else {
Err(Error::Generic("unable to parse fingerprint"))
Err(Error::from("unable to parse fingerprint"))
}
}
}
Expand Down Expand Up @@ -354,7 +354,7 @@ impl Crypto for GpgMe {
if let Some(key) = key_opt {
key.fingerprint()?.to_owned()
} else {
return Err(Error::Generic("no valid signing key"));
return Err(Error::from("no valid signing key"));
}
}
};
Expand Down Expand Up @@ -505,7 +505,7 @@ fn download_keys(recipient_key_id: &str) -> Result<String> {
"https://keys.openpgp.org/vks/v1/by-fingerprint/{}",
&recipient_key_id[2..]
),
_ => return Err(Error::Generic("key id is not 16 or 40 hex chars")),
_ => return Err(Error::from("key id is not 16 or 40 hex chars")),
};

Ok(reqwest::blocking::get(url)?.text()?)
Expand Down Expand Up @@ -564,7 +564,7 @@ fn find(
key_ring: &HashMap<Fingerprint, Arc<Cert>>,
recipient: Option<&KeyHandle>,
) -> Result<Arc<Cert>> {
let recipient = recipient.as_ref().ok_or(Error::Generic("No recipient"))?;
let recipient = recipient.as_ref().ok_or(Error::from("No recipient"))?;

match recipient {
KeyHandle::Fingerprint(fpr) => match fpr {
Expand All @@ -579,7 +579,7 @@ fn find(
}
}
sequoia_openpgp::Fingerprint::Unknown { .. } => {
return Err(Error::Generic("unknown fingerprint version"));
return Err(Error::from("unknown fingerprint version"));
}
_ => {}
},
Expand All @@ -592,13 +592,13 @@ fn find(
}
}
KeyID::Invalid(_) => {
return Err(Error::Generic("Invalid key ID"));
return Err(Error::from("Invalid key ID"));
}
_ => {}
},
}

Err(Error::Generic("key not found in keyring"))
Err(Error::from("key not found in keyring"))
}

impl DecryptionHelper for Helper<'_> {
Expand Down Expand Up @@ -764,7 +764,7 @@ impl Sequoia {
match self.key_ring.get(fp) {
Some(cert) => result.push(cert.clone()),
None => {
return Err(Error::GenericDyn(format!(
return Err(Error::from(format!(
"Recipient with key id {} not found",
recipient.key_id
)));
Expand Down Expand Up @@ -820,7 +820,7 @@ impl Crypto for Sequoia {
let decrypt_key = self
.key_ring
.get(&self.user_key_id)
.ok_or(Error::Generic("no key for user found"))?;
.ok_or(Error::from("no key for user found"))?;

if decrypt_key.is_tsk() {
// Make a helper that that feeds the recipient's secret key to the
Expand Down Expand Up @@ -920,7 +920,7 @@ impl Crypto for Sequoia {
let tsk = self
.key_ring
.get(&self.user_key_id)
.ok_or(Error::Generic("no key for user found"))?;
.ok_or(Error::from("no key for user found"))?;

// Get the keypair to do the signing from the Cert.
let keypair = tsk
Expand Down Expand Up @@ -1044,7 +1044,7 @@ impl Crypto for Sequoia {
}
}

Err(Error::GenericDyn(format!("no key found for {key_id}")))
Err(Error::from(format!("no key found for {key_id}")))
}

fn get_all_trust_items(&self) -> Result<HashMap<Fingerprint, OwnerTrustLevel>> {
Expand Down
Loading
Loading