summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorquentin konieczko <konieczko@gmail.com>2023-01-17 09:47:19 +0100
committerquentin konieczko <konieczko@gmail.com>2023-01-17 09:47:19 +0100
commit90fb9f1aad1d6f546362c395134e6c46923f2102 (patch)
treee5030758a0f17cccd9d37eacbcfaad7b52f38c7c /src
parent8f97774d2fa6f8fbe3308e0d96d738f9181ecd2c (diff)
menu to input password
Diffstat (limited to 'src')
-rw-r--r--src/cryptsetup.rs35
-rw-r--r--src/event_exec.rs27
-rw-r--r--src/mode.rs13
-rw-r--r--src/status.rs6
-rw-r--r--src/tab.rs2
-rw-r--r--src/term_manager.rs6
6 files changed, 61 insertions, 28 deletions
diff --git a/src/cryptsetup.rs b/src/cryptsetup.rs
index 01a3d3f..8146c5b 100644
--- a/src/cryptsetup.rs
+++ b/src/cryptsetup.rs
@@ -5,21 +5,21 @@ use crate::fm_error::{FmError, FmResult};
#[derive(Debug, Clone, Copy)]
pub enum PasswordKind {
- SUDO,
- CRYPTSETUP,
+ SUDO(usize),
+ CRYPTSETUP(usize),
}
impl std::fmt::Display for PasswordKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let asker = match self {
- Self::SUDO => "sudo",
- Self::CRYPTSETUP => "cryptsetup",
+ Self::SUDO(_) => "sudo",
+ Self::CRYPTSETUP(_) => "cryptsetup",
};
write!(f, "{}", asker)
}
}
-#[derive(Default)]
+#[derive(Default, Clone, Debug)]
pub struct PasswordHolder {
sudo: Option<String>,
cryptsetup: Option<String>,
@@ -38,6 +38,14 @@ impl PasswordHolder {
self
}
+ pub fn set_sudo(&mut self, password: String) {
+ self.sudo = Some(password)
+ }
+
+ pub fn set_cryptsetup(&mut self, passphrase: String) {
+ self.cryptsetup = Some(passphrase)
+ }
+
/// Reads the cryptsetup password
pub fn cryptsetup(&self) -> FmResult<String> {
Ok(self
@@ -122,7 +130,7 @@ fn sudo(args: &[String]) -> FmResult<(String, String)> {
))
}
-#[derive(Debug, Default)]
+#[derive(Debug, Default, Clone)]
pub struct CryptoDevice {
fs_type: String,
path: String,
@@ -280,3 +288,18 @@ impl CryptoDevice {
Ok(s)
}
}
+
+#[derive(Debug, Clone, Default)]
+pub struct DeviceOpener {
+ pub cryptdevice: CryptoDevice,
+ pub password_holder: PasswordHolder,
+}
+
+impl DeviceOpener {
+ pub fn from_line(line: &str) -> FmResult<Self> {
+ Ok(Self {
+ cryptdevice: CryptoDevice::from_line(line)?,
+ password_holder: PasswordHolder::default(),
+ })
+ }
+}
diff --git a/src/event_exec.rs b/src/event_exec.rs
index 74d7065..a5f4216 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -13,10 +13,10 @@ use crate::constant_strings_paths::DEFAULT_DRAGNDROP;
use crate::constant_strings_paths::NVIM_RPC_SENDER;
use crate::content_window::RESERVED_ROWS;
use crate::copy_move::CopyMove;
+use crate::cryptsetup::PasswordKind;
use crate::fileinfo::FileKind;
use crate::filter::FilterKind;
use crate::fm_error::{FmError, FmResult};
-use crate::mode::EncryptedDrive;
use crate::mode::Navigate;
use crate::mode::{InputSimple, MarkAction, Mode, NeedConfirmation};
use crate::opener::execute_in_child;
@@ -1266,7 +1266,7 @@ impl EventExec {
Mode::Navigate(Navigate::History) => EventExec::exec_history(status.selected())?,
Mode::Navigate(Navigate::Shortcut) => EventExec::exec_shortcut(status.selected())?,
Mode::Navigate(Navigate::Trash) => EventExec::event_trash_restore_file(status)?,
- Mode::Navigate(Navigate::EncryptedDrive(_)) => {
+ Mode::Navigate(Navigate::EncryptedDrive) => {
EventExec::event_toggle_encrypted_drive(status)?
}
Mode::InputCompleted(InputCompleted::Exec) => EventExec::exec_exec(status.selected())?,
@@ -1551,15 +1551,32 @@ impl EventExec {
pub fn event_encrypted_drive(status: &mut Status) -> FmResult<()> {
status
.selected()
- .set_mode(Mode::Navigate(Navigate::EncryptedDrive(
- EncryptedDrive::PickDevices,
- )));
+ .set_mode(Mode::Navigate(Navigate::EncryptedDrive));
Ok(())
}
pub fn event_toggle_encrypted_drive(_status: &mut Status) -> FmResult<()> {
Ok(())
}
+
+ pub fn exec_password_store(status: &mut Status, password_kind: PasswordKind) -> FmResult<()> {
+ let password = status.selected_non_mut().input.string();
+ if let Some(devices) = &mut status.encrypted_devices {
+ match password_kind {
+ PasswordKind::SUDO(index) => {
+ let device_opener = &mut devices[index];
+ device_opener.password_holder.set_sudo(password)
+ }
+ PasswordKind::CRYPTSETUP(index) => {
+ let device_opener = &mut devices[index];
+ device_opener.password_holder.set_cryptsetup(password)
+ }
+ }
+ }
+ status.selected().reset_mode();
+ status.clear_flags_and_reset_view()?;
+ Ok(())
+ }
}
fn string_to_path(path_string: &str) -> FmResult<path::PathBuf> {
diff --git a/src/mode.rs b/src/mode.rs
index eddeada..e2405f6 100644
--- a/src/mode.rs
+++ b/src/mode.rs
@@ -52,13 +52,6 @@ impl std::fmt::Display for NeedConfirmation {
}
}
-#[derive(Clone, Copy, Debug)]
-pub enum EncryptedDrive {
- PickDevices,
- OpenMount,
- UmountClose,
-}
-
/// Different modes in which the user is expeted to type something.
/// It may be a new filename, a mode (aka an octal permission),
/// the name of a new file, of a new directory,
@@ -99,7 +92,7 @@ pub enum Navigate {
///
Trash,
///
- EncryptedDrive(EncryptedDrive),
+ EncryptedDrive,
}
/// Different mode in which the application can be.
@@ -150,8 +143,8 @@ impl fmt::Display for Mode {
Mode::Navigate(Navigate::History) => write!(f, "History :"),
Mode::Navigate(Navigate::Shortcut) => write!(f, "Shortcut :"),
Mode::Navigate(Navigate::Trash) => write!(f, "Trash :"),
- Mode::Navigate(Navigate::EncryptedDrive(encrypted_drive)) => {
- write!(f, "{:?}", encrypted_drive)
+ Mode::Navigate(Navigate::EncryptedDrive) => {
+ write!(f, "Encrypted devices :")
}
Mode::NeedConfirmation(_) => write!(f, "Y/N :"),
Mode::Preview => write!(f, "Preview : "),
diff --git a/src/status.rs b/src/status.rs
index 9856663..1eb6823 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -14,7 +14,7 @@ use crate::args::Args;
use crate::config::{Colors, Config};
use crate::constant_strings_paths::OPENER_PATH;
use crate::copy_move::{copy_move, CopyMove};
-use crate::cryptsetup::{filter_crypto_devices_lines, get_devices, CryptoDevice};
+use crate::cryptsetup::{filter_crypto_devices_lines, get_devices, DeviceOpener};
use crate::flagged::Flagged;
use crate::fm_error::{FmError, FmResult};
use crate::marks::Marks;
@@ -60,7 +60,7 @@ pub struct Status {
/// The trash
pub trash: Trash,
pub config_colors: Colors,
- pub encrypted_devices: Option<Vec<CryptoDevice>>,
+ pub encrypted_devices: Option<Vec<DeviceOpener>>,
}
impl Status {
@@ -324,7 +324,7 @@ impl Status {
self.encrypted_devices = Some(
filter_crypto_devices_lines(get_devices()?, "crypto")
.iter()
- .map(|line| CryptoDevice::from_line(line))
+ .map(|line| DeviceOpener::from_line(line))
.filter_map(|r| r.ok())
.collect(),
);
diff --git a/src/tab.rs b/src/tab.rs
index 573b23b..505194b 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -27,7 +27,7 @@ pub struct Tab {
pub previous_mode: Mode,
/// The indexes of displayed file
pub window: ContentWindow,
- /// Files marked as flagged
+ /// The typed input by the user
pub input: Input,
/// Files in current path
pub path_content: PathContent,
diff --git a/src/term_manager.rs b/src/term_manager.rs
index c155cb2..df986fa 100644
--- a/src/term_manager.rs
+++ b/src/term_manager.rs
@@ -15,7 +15,7 @@ use crate::constant_strings_paths::{
use crate::content_window::ContentWindow;
use crate::fileinfo::{fileinfo_attr, FileInfo};
use crate::fm_error::{FmError, FmResult};
-use crate::mode::{EncryptedDrive, InputSimple, MarkAction, Mode, Navigate, NeedConfirmation};
+use crate::mode::{InputSimple, MarkAction, Mode, Navigate, NeedConfirmation};
use crate::preview::{Preview, TextKind, Window};
use crate::selectable_content::SelectableContent;
use crate::status::Status;
@@ -366,7 +366,7 @@ impl<'a> Draw for WinSecondary<'a> {
Mode::Navigate(Navigate::History) => self.destination(canvas, &self.tab.history),
Mode::Navigate(Navigate::Shortcut) => self.destination(canvas, &self.tab.shortcut),
Mode::Navigate(Navigate::Trash) => self.trash(canvas, &self.status.trash),
- Mode::Navigate(Navigate::EncryptedDrive(EncryptedDrive::PickDevices)) => {
+ Mode::Navigate(Navigate::EncryptedDrive) => {
self.encrypted_devices(self.status, self.tab, canvas)
}
Mode::NeedConfirmation(confirmed_mode) => {
@@ -523,7 +523,7 @@ impl<'a> WinSecondary<'a> {
if let Some(encrypted_devices) = &status.encrypted_devices {
for (i, device) in encrypted_devices.iter().enumerate() {
let row = calc_line_row(i, tab) + 2;
- canvas.print(row, 3, &device.as_string()?)?;
+ canvas.print(row, 3, &device.cryptdevice.as_string()?)?;
}
}
Ok(())