2021-03-25 18:46:07 +00:00
|
|
|
use std::path::Path;
|
2021-02-18 09:48:38 +00:00
|
|
|
|
2021-04-02 17:51:49 +00:00
|
|
|
use crate::string_type::String;
|
2021-02-14 17:12:27 +00:00
|
|
|
use mime_guess::Mime;
|
|
|
|
|
2021-02-18 09:48:38 +00:00
|
|
|
use crate::inspectors::mime_extension_lookup;
|
|
|
|
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Information about a scanned file.
|
2021-03-25 18:46:07 +00:00
|
|
|
pub struct Findings<'a> {
|
2021-02-28 14:06:05 +00:00
|
|
|
/// The location of the scanned file.
|
2021-03-25 18:46:07 +00:00
|
|
|
pub file: &'a Path,
|
2021-02-28 14:06:05 +00:00
|
|
|
/// Whether or not the file's extension is valid for its mimetype.
|
2021-02-14 17:12:27 +00:00
|
|
|
pub valid: bool,
|
2021-02-28 14:06:05 +00:00
|
|
|
/// The file's mimetype.
|
2021-02-14 17:12:27 +00:00
|
|
|
pub mime: Mime,
|
|
|
|
}
|
|
|
|
|
2021-03-25 18:46:07 +00:00
|
|
|
impl<'a> Findings<'a> {
|
2021-03-11 17:26:35 +00:00
|
|
|
pub fn recommended_extension(&self) -> Option<String> {
|
|
|
|
mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].to_owned())
|
2021-02-14 17:12:27 +00:00
|
|
|
}
|
|
|
|
}
|