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
4 changes: 1 addition & 3 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::widgets::list::StatefulList;
pub struct App {
pub items: StatefulList<String>,
pub key_details: Option<String>,
pub popup: bool,
pub scroll_state: usize,
pub current_dir: PathBuf,
pub help_items: StatefulList<String>,
Expand Down Expand Up @@ -54,13 +53,12 @@ impl App {
);
help_descriptions.insert(
"- Esc: Go up a directory".to_string(),
"Go up a directory\nNote: it will be able in a future update to abort from an operation".to_string(),
"Go up a directory\nNote: it will be available in a future update to abort from an operation".to_string(),
);

App {
items: StatefulList::with_items(items),
key_details: None,
popup: false,
scroll_state: 0,
current_dir,
help_items: StatefulList::with_items(vec![
Expand Down
4 changes: 2 additions & 2 deletions src/app/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ pub fn run_app(
KeyCode::Left => app.items.unselect(),
KeyCode::Down => {
if let Some(details) = &app.key_details {
app.scroll_state =
(app.scroll_state + 1).min(details.lines().count() - 1);
app.scroll_state = (app.scroll_state + 1)
.min(details.lines().count().saturating_sub(1));
} else {
app.items.next();
}
Expand Down
13 changes: 6 additions & 7 deletions src/sequoia_openpgp/certificate_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::utils::parse_iso8601_duration::parse_iso8601_duration;
/// Sanitize a user ID for use as a filename component.
/// Replaces `..`, `/`, and `\` with `_` to prevent path traversal.
fn sanitize_for_path(input: &str) -> String {
input.replace("..", "_").replace(['/', '\\'], "_")
input.replace("..", "_").replace(['/', '\\', ' '], "_")
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -357,14 +357,12 @@ impl CertificateManager {
// Note: certificate on the context of the sequoia openpgp crate means the public key that can be shared
let home_dir = home::home_dir()
.ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
let key_path =
format!("{}/.pgpman/secrets/{}.pgp", &home_dir.display(), safe_uid).replace(" ", "");
let key_path = format!("{}/.pgpman/secrets/{}.pgp", &home_dir.display(), safe_uid);
let revcert_path = format!(
"{}/.pgpman/revocation/{}.rev",
&home_dir.display(),
safe_uid
)
.replace(" ", "");
);
// export key to path
{
if let Some(w) = create_secret_file(Some(key_path.as_str()))? {
Expand All @@ -388,8 +386,7 @@ impl CertificateManager {
"{}/.pgpman/certificates/{}.pgp",
&home_dir.display(),
safe_uid
)
.replace(" ", "");
);
{
if let Some(mut w) = create_file(Some(cert_path.as_str()))? {
key.strip_secret_key_material()
Expand Down Expand Up @@ -449,6 +446,8 @@ impl CertificateManager {
if let Some(mut out) = create_secret_file(Some(secret_key))? {
key.as_tsk().armored().serialize(&mut out)?;
}
} else {
return Err(anyhow::anyhow!("Passwords do not match!"));
}
Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ impl<T> StatefulList<T> {

/// Selects the next item.
pub fn next(&mut self) {
if self.items.is_empty() {
return;
}
let i = match self.state.selected() {
Some(i) => {
if i >= self.items.len() - 1 {
Expand All @@ -43,6 +46,9 @@ impl<T> StatefulList<T> {

/// Selects the previous item.
pub fn previous(&mut self) {
if self.items.is_empty() {
return;
}
let i = match self.state.selected() {
Some(i) => {
if i == 0 {
Expand Down
8 changes: 4 additions & 4 deletions tests/certificate_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ fn manager() -> CertificateManager {

/// Mirror the sanitization logic from `certificate_manager::sanitize_for_path`.
fn sanitize_for_path(input: &str) -> String {
input.replace("..", "_").replace(['/', '\\'], "_")
input.replace("..", "_").replace(['/', '\\', ' '], "_")
}

/// Helper to compute the paths that `generate_keypair` writes to in ~/.pgpman/.
fn pgpman_paths(uid: &str) -> (String, String, String) {
let home = home::home_dir().unwrap();
let safe = sanitize_for_path(uid);
(
format!("{}/.pgpman/secrets/{}.pgp", home.display(), safe).replace(' ', ""),
format!("{}/.pgpman/revocation/{}.rev", home.display(), safe).replace(' ', ""),
format!("{}/.pgpman/certificates/{}.pgp", home.display(), safe).replace(' ', ""),
format!("{}/.pgpman/secrets/{}.pgp", home.display(), safe),
format!("{}/.pgpman/revocation/{}.rev", home.display(), safe),
format!("{}/.pgpman/certificates/{}.pgp", home.display(), safe),
)
}

Expand Down