diff --git a/src/extension_set.rs b/src/extension_set.rs deleted file mode 100644 index ddfb5c4..0000000 --- a/src/extension_set.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! Sets of extensions for use with [Parameter](crate::parameters::Parameters)'s `-E` flag. -use clap::Clap; - -#[derive(Clap, PartialEq, Debug)] -pub enum ExtensionSet { - /// Extensions used for image file formats, such as `png`, `jpeg`, `webp`, etc. - Images, - /// Extensions used for audio file formats, such as `mp3`, `ogg`, `flac`, etc. - Audio, - /// Extensions used for video file formats, such as `mkv`, `mp4`, `mov`, etc. - Videos, - /// Extensions used for media file formats. This acts as a combination of the [Images](ExtensionSet::Images), - /// [Audio](ExtensionSet::Audio) and [Videos](ExtensionSet::Videos) variants. - Media, - /// Extensions used for document file formats, such as `pdf`, `odt`, `docx`, etc. - Documents, - /// Extensions used for text file formats, such as `txt`, `toml`, `html`, etc. - Text, - /// Extensions used for archive file formats, such as `zip`, `zst`, `gz`, etc. - Archives, - /// Extensions used for system file formats, such as `mbr`, `crash`, `dll`, etc. - System, -} - -impl ExtensionSet { - /// The list of known extensions for this `ExtensionSet`. - pub fn extensions(&self) -> Vec<&str> { - match self { - Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), - Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(), - Self::Videos => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(), - Self::Media => [ - Self::Images.extensions(), - Self::Audio.extensions(), - Self::Videos.extensions(), - ] - .concat(), - Self::Documents => vec![ - "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", - "pages", "key", "numbers", - ], - Self::Text => mime_guess::get_mime_extensions_str("text/*").unwrap().to_vec(), - // many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used - // somehow to extract extensions for compressed files from mime_guess? - Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz", "rpa"], - Self::System => vec![ - "com", "dll", "exe", "sys", "reg", "nt", "cpl", "msi", "efi", "bio", "rcv", "mbr", "sbf", "grub", "ko", - "dylib", "pdb", "hdmp", "crash", - ], - } - } -} diff --git a/src/main.rs b/src/main.rs index d7eb6f7..d23642d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,6 @@ use crate::mime_db::MimeDb; use crate::parameters::{OutputFormat, ScanOpts}; use crate::scan_error::ScanError; -mod extension_set; mod findings; mod formats; mod inspectors; diff --git a/src/parameters.rs b/src/parameters.rs index cf8b306..f4e1e83 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -1,6 +1,5 @@ //! [Clap] struct used to parse command line arguments. -use crate::extension_set::ExtensionSet; use crate::string_type::String as StringType; use cfg_if::cfg_if; use clap::{AppSettings, Clap}; @@ -125,3 +124,55 @@ impl Parameters { } } } + +/// Sets of extensions for use with [Parameter](crate::parameters::Parameters)'s `-E` flag. +#[derive(Clap, PartialEq, Debug)] +pub enum ExtensionSet { + /// Extensions used for image file formats, such as `png`, `jpeg`, `webp`, etc. + Images, + /// Extensions used for audio file formats, such as `mp3`, `ogg`, `flac`, etc. + Audio, + /// Extensions used for video file formats, such as `mkv`, `mp4`, `mov`, etc. + Videos, + /// Extensions used for media file formats. This acts as a combination of the [Images](ExtensionSet::Images), + /// [Audio](ExtensionSet::Audio) and [Videos](ExtensionSet::Videos) variants. + Media, + /// Extensions used for document file formats, such as `pdf`, `odt`, `docx`, etc. + Documents, + /// Extensions used for text file formats, such as `txt`, `toml`, `html`, etc. + Text, + /// Extensions used for archive file formats, such as `zip`, `zst`, `gz`, etc. + Archives, + /// Extensions used for system file formats, such as `mbr`, `crash`, `dll`, etc. + System, +} + +impl ExtensionSet { + /// The list of known extensions for this `ExtensionSet`. + pub fn extensions(&self) -> Vec<&str> { + match self { + Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), + Self::Audio => mime_guess::get_mime_extensions_str("audio/*").unwrap().to_vec(), + Self::Videos => mime_guess::get_mime_extensions_str("video/*").unwrap().to_vec(), + Self::Media => [ + Self::Images.extensions(), + Self::Audio.extensions(), + Self::Videos.extensions(), + ] + .concat(), + Self::Documents => vec![ + "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", + "pages", "key", "numbers", + ], + Self::Text => mime_guess::get_mime_extensions_str("text/*").unwrap().to_vec(), + // many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used + // somehow to extract extensions for compressed files from mime_guess? + Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz", "rpa"], + Self::System => vec![ + "com", "dll", "exe", "sys", "reg", "nt", "cpl", "msi", "efi", "bio", "rcv", "mbr", "sbf", "grub", "ko", + "dylib", "pdb", "hdmp", "crash", + ], + } + } +} + diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 48b697c..5221e45 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -278,7 +278,7 @@ fn outputs_move_commands() { #[test] /// Ensure that the Media extension set contains all (is a superset) of Audio, Video, and Images. fn media_contains_audio_video_images() { - use crate::extension_set::ExtensionSet::{Audio, Images, Media, Videos}; + use crate::parameters::ExtensionSet::{Audio, Images, Media, Videos}; let media_exts = Media.extensions(); // assert every extension in the audio/video/image sets is contained in the media set