use crate::Compiler::AST::{DixScript};
use std::collections::HashMap;
pub type AuditorResult<T> = Result<T, String>;
#[derive(Debug, Clone)]
pub struct AuditResult {
pub is_success: bool,
pub audit_file_path: String,
pub audit_id: String,
pub errors: Vec<String>,
}
impl AuditResult {
pub fn success(audit_file_path: String, audit_id: String) -> Self {
AuditResult {
is_success: true,
audit_file_path,
audit_id,
errors: Vec::new(),
}
}
pub fn failure(errors: Vec<String>) -> Self {
AuditResult {
is_success: false,
audit_file_path: String::new(),
audit_id: String::new(),
errors,
}
}
}
#[derive(Debug, Clone)]
pub struct AuditEntry {
pub compilation_id: String,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub source_checksum: String,
pub previous_checksum: Option<String>,
pub status: String, pub modules_executed: Vec<String>,
pub execution_time_ms: f64,
pub changes_detected: Vec<AuditChange>,
pub changes_summary: Option<String>,
pub steps: Vec<AuditStep>,
pub decryption_attempts: Vec<DecryptionAttempt>,
}
impl AuditEntry {
pub fn new() -> Self {
AuditEntry {
compilation_id: uuid::Uuid::new_v4().to_string()[..8].to_string(),
timestamp: chrono::Utc::now(),
source_checksum: String::new(),
previous_checksum: None,
status: "SUCCESS".to_string(),
modules_executed: Vec::new(),
execution_time_ms: 0.0,
changes_detected: Vec::new(),
changes_summary: None,
steps: Vec::new(),
decryption_attempts: Vec::new(),
}
}
}
impl Default for AuditEntry {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct DecryptionAttempt {
pub timestamp: chrono::DateTime<chrono::Utc>,
pub success: bool,
pub details: String,
pub encrypted_size: usize,
pub decrypted_size: usize,
pub duration_ms: f64,
}
impl DecryptionAttempt {
pub fn new(
success: bool,
details: String,
encrypted_size: usize,
decrypted_size: usize,
duration_ms: f64,
) -> Self {
DecryptionAttempt {
timestamp: chrono::Utc::now(),
success,
details,
encrypted_size,
decrypted_size,
duration_ms,
}
}
}
#[derive(Debug, Clone)]
pub struct AuditChange {
pub section: String,
pub path: String,
pub change_type: String, pub old_value: Option<String>,
pub new_value: Option<String>,
}
impl AuditChange {
pub fn new(
section: String,
path: String,
change_type: String,
old_value: Option<String>,
new_value: Option<String>,
) -> Self {
AuditChange {
section,
path,
change_type,
old_value,
new_value,
}
}
}
#[derive(Debug, Clone)]
pub struct AuditStep {
pub step_name: String,
pub details: String,
pub input_size: usize,
pub output_size: usize,
pub duration_ms: f64,
}
impl AuditStep {
pub fn new(
step_name: String,
details: String,
input_size: usize,
output_size: usize,
duration_ms: f64,
) -> Self {
AuditStep {
step_name,
details,
input_size,
output_size,
duration_ms,
}
}
}
pub trait IAuditor {
fn module_name(&self) -> &str;
fn initialize(&mut self, config: HashMap<String, String>);
fn start_audit(&mut self, ast: &DixScript, binary_data: &[u8]) -> AuditorResult<AuditResult>;
fn log_step(
&mut self,
step_name: &str,
details: &str,
input_size: usize,
output_size: usize,
duration_ms: f64,
);
fn log_decryption_attempt(
&mut self,
success: bool,
details: &str,
encrypted_size: usize,
decrypted_size: usize,
duration_ms: f64,
);
fn finalize_audit(&mut self) -> AuditorResult<()>;
fn validate(&self) -> Result<(), String>;
fn get_metadata(&self) -> HashMap<String, String>;
fn priority(&self) -> i32;
}