pub mod secure;
pub mod strategy;
pub use secure::SecureRedactionStrategy;
pub use strategy::{RedactionResult, RedactionStrategy, RedactionTarget};
use crate::error::{RedactorError, RedactorResult};
use std::path::Path;
pub struct RedactionService {
strategy: Box<dyn RedactionStrategy>,
}
impl RedactionService {
pub fn new(strategy: Box<dyn RedactionStrategy>) -> Self {
Self { strategy }
}
pub fn with_secure_strategy() -> Self {
Self::new(Box::new(SecureRedactionStrategy::default()))
}
pub fn redact(
&self,
input: &Path,
output: &Path,
targets: &[RedactionTarget],
) -> RedactorResult<RedactionResult> {
if !input.exists() {
return Err(RedactorError::Io {
path: input.to_path_buf(),
source: std::io::Error::new(
std::io::ErrorKind::NotFound,
"Input file does not exist",
),
});
}
if targets.is_empty() {
return Err(RedactorError::InvalidInput {
parameter: "targets".to_string(),
reason: "No redaction targets specified".to_string(),
});
}
self.strategy.redact(input, output, targets)
}
pub fn extract_text(&self, input: &Path) -> RedactorResult<String> {
self.strategy.extract_text(input)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_service_creation() {
let _service = RedactionService::with_secure_strategy();
}
}