use super::output_root::OutputRoot;
use crate::ExtractionOptions;
use crate::ExtractionReport;
use crate::ProgressCallback;
use crate::Result;
#[cfg(test)]
use crate::VerificationOptions;
#[cfg(test)]
use crate::inspection::ArchiveManifest;
#[cfg(test)]
use crate::inspection::VerificationReport;
pub(crate) mod sealed {
pub(crate) trait Sealed {}
}
pub(crate) trait ArchiveFormat: sealed::Sealed {
fn extract<'o>(
self,
output: impl Into<OutputRoot<'o>>,
options: &ExtractionOptions,
progress: &mut dyn ProgressCallback,
) -> Result<ExtractionReport>;
#[cfg(test)]
fn list(self) -> Result<ArchiveManifest>;
#[cfg(test)]
fn verify(self, options: VerificationOptions) -> Result<VerificationReport>;
}
#[cfg(test)]
mod tests {
use super::*;
struct TestFormat;
impl sealed::Sealed for TestFormat {}
impl ArchiveFormat for TestFormat {
fn extract<'o>(
self,
_output: impl Into<OutputRoot<'o>>,
_options: &ExtractionOptions,
_progress: &mut dyn ProgressCallback,
) -> Result<ExtractionReport> {
Ok(ExtractionReport::new())
}
fn list(self) -> Result<ArchiveManifest> {
use crate::formats::detect::ArchiveType;
Ok(ArchiveManifest::new(ArchiveType::Tar))
}
fn verify(self, _options: VerificationOptions) -> Result<VerificationReport> {
let config = crate::SecurityConfig::default();
let manifest = self.list()?;
Ok(crate::inspection::verify::verify_manifest(
&manifest, &config, None,
))
}
}
#[test]
#[allow(clippy::unwrap_used)]
fn test_trait_extract_returns_report() {
let format = TestFormat;
let temp = tempfile::TempDir::new().unwrap();
let options = ExtractionOptions::default();
let mut noop = crate::NoopProgress;
let report = format.extract(temp.path(), &options, &mut noop).unwrap();
assert_eq!(report.files_extracted, 0);
}
#[test]
#[allow(clippy::unwrap_used)]
fn test_trait_list_returns_empty_manifest() {
let format = TestFormat;
let manifest = format.list().unwrap();
assert_eq!(manifest.total_entries(), 0);
assert_eq!(manifest.total_size(), 0);
}
#[test]
#[allow(clippy::unwrap_used)]
fn test_trait_verify_returns_clean_report_for_empty_archive() {
let format = TestFormat;
let report = format
.verify(crate::VerificationOptions::default())
.unwrap();
assert_eq!(report.total_entries(), 0);
assert!(report.is_safe());
}
}