Get options for filesystem
This commit is contained in:
parent
8418d1795d
commit
6702757eaa
|
@ -558,6 +558,7 @@ dependencies = [
|
|||
"fuser",
|
||||
"log",
|
||||
"rustcryptfs-lib",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
|
|
@ -9,4 +9,5 @@ edition = "2021"
|
|||
fuser = "0.11"
|
||||
log = "0.4"
|
||||
rustcryptfs-lib = { path = "../rustcryptfs-lib" }
|
||||
thiserror = "1.0"
|
||||
thiserror = "1.0"
|
||||
serde_json = "1.0"
|
|
@ -1,20 +1,36 @@
|
|||
use std::path::Path;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use fuser::Filesystem;
|
||||
use rustcryptfs_lib::config::CryptConf;
|
||||
use rustcryptfs_lib::{config::CryptConf, filename::FilenameDecoder};
|
||||
|
||||
pub struct EncryptedFs {}
|
||||
use crate::error::Result;
|
||||
|
||||
pub struct EncryptedFs {
|
||||
master_key: Vec<u8>,
|
||||
filename_decoder: FilenameDecoder,
|
||||
}
|
||||
|
||||
impl EncryptedFs {
|
||||
pub fn new<P>(path: P) -> Self
|
||||
pub fn new<P>(path: P, password: &str) -> Result<Self>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
let path = path.as_ref();
|
||||
|
||||
pub fn new_from_config(config: &CryptConf) -> Self {
|
||||
Self {}
|
||||
let conf_path = path.join("gocryptfs.conf");
|
||||
|
||||
let content = fs::read_to_string(conf_path)?;
|
||||
|
||||
let conf: CryptConf = serde_json::from_str(&content)?;
|
||||
|
||||
let master_key = conf.get_master_key(password.as_bytes())?;
|
||||
|
||||
let filename_decoder = FilenameDecoder::new(&master_key)?;
|
||||
|
||||
Ok(Self {
|
||||
master_key,
|
||||
filename_decoder,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn mount<P>(self, mountpoint: P)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
use thiserror::Error;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
IoError(#[from] std::io::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
JsonError(#[from] serde_json::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
RustCryptFsError(#[from] rustcryptfs_lib::error::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
RustCryptFsFilenameError(#[from] rustcryptfs_lib::error::FilenameDecryptError),
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
mod encrypted_filesystem;
|
||||
pub mod error;
|
||||
|
||||
pub use encrypted_filesystem::EncryptedFs;
|
|
@ -108,7 +108,7 @@ fn decrypt_file(c: &DecryptCommand) -> anyhow::Result<()> {
|
|||
fn mount(mount: &MountCommand) -> anyhow::Result<()> {
|
||||
use rustcryptfs_linux::EncryptedFs;
|
||||
|
||||
let fs = EncryptedFs::new(&mount.path);
|
||||
let fs = EncryptedFs::new(&mount.path, mount.password.as_ref().unwrap())?;
|
||||
|
||||
fs.mount(&mount.mountpoint);
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue