From 4eb66cfad42067231d4c5c13850c30558ca0af76 Mon Sep 17 00:00:00 2001 From: oupson Date: Thu, 6 Oct 2022 17:07:37 +0200 Subject: [PATCH] Remove useless io mod --- rustcryptfs-lib/src/io/mod.rs | 155 ---------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 rustcryptfs-lib/src/io/mod.rs diff --git a/rustcryptfs-lib/src/io/mod.rs b/rustcryptfs-lib/src/io/mod.rs deleted file mode 100644 index 5852394..0000000 --- a/rustcryptfs-lib/src/io/mod.rs +++ /dev/null @@ -1,155 +0,0 @@ -use std::{ - error::Error, - fs::File, - io::Read, - path::{Path, PathBuf}, -}; - -use crate::filename::{EncodedFilename, FilenameDecoder}; - -#[derive(Debug)] -pub struct DirCache { - filename: String, - dir_iv: [u8; 16], - dir_entries: Vec, -} - -impl DirCache { - pub fn load_from_path

(path: P) -> Self - where - P: AsRef, - { - let path = path.as_ref(); - - let mut dir_iv = [0u8; 16]; - { - let dir_iv_path = path.join("gocryptfs.diriv"); - - let mut file = File::open(dir_iv_path).unwrap(); - - file.read_exact(&mut dir_iv).unwrap(); - } - - let dir_entries = path - .read_dir() - .unwrap() - .filter_map(|f| { - if let Ok(entry) = f { - if entry.file_name() != "gocryptfs.conf" - && entry.file_name() != "gocryptfs.diriv" - { - Some(entry) - } else { - None - } - } else { - None - } - }) - .map(|f| DirEntry::try_from(f.path().as_path())) - .filter_map(|f| f.ok()) - .collect(); - - Self { - filename: path.to_string_lossy().to_string(), - dir_iv, - dir_entries, - } - } - - pub fn lookup

( - &self, - filename_decoder: &FilenameDecoder, - decrypted_path: P, - ) -> Option - where - P: AsRef, - { - let decrypted_path = decrypted_path.as_ref(); - - let mut components = decrypted_path.components(); - - let component = components.next().expect("lol"); - - let decoder = filename_decoder.get_decoder_for_dir(&self.dir_iv); - - let segment = decoder - .encrypt_filename(component.as_os_str().to_str().unwrap()) - .expect("lol"); - - let segment_path = match segment { - EncodedFilename::ShortFilename(filename) => PathBuf::from(filename), - EncodedFilename::LongFilename(long_filename) => PathBuf::from(long_filename.filename), - }; - - if segment_path.is_dir() { - let (size, _) = components.size_hint(); - - if size > 0 { - unimplemented!() - } else { - unimplemented!() - //None - } - } else { - // component.as_path() - unimplemented!() - }; - - } - - fn lookup_internal

( - &self, - filename_decoder: &FilenameDecoder, - decrypted_path: P, - dir: &DirCache, - ) -> Option - where - P: AsRef, - { - unimplemented!() - } -} - -#[derive(Debug)] -pub enum DirEntry { - Dir(DirCache), - File(String), -} - -impl DirEntry { - /// Returns `true` if the dir entry is [`Dir`]. - /// - /// [`Dir`]: DirEntry::Dir - #[must_use] - pub fn is_dir(&self) -> bool { - matches!(self, Self::Dir(..)) - } - - /// Returns `true` if the dir entry is [`File`]. - /// - /// [`File`]: DirEntry::File - #[must_use] - pub fn is_file(&self) -> bool { - matches!(self, Self::File(..)) - } -} - -impl TryFrom<&Path> for DirEntry { - type Error = Box; // TODO - - fn try_from(path: &Path) -> Result { - Ok(if path.is_dir() { - DirEntry::Dir(DirCache::load_from_path(path)) - } else { - DirEntry::File( - path.components() - .last() - .unwrap() - .as_os_str() - .to_string_lossy() - .to_string(), - ) - }) - } -}