37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use serde::{Serialize, Deserialize};
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
use crate::error::CliError;
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct AuditLog {
|
|
pub timestamp: u64,
|
|
pub operator: String,
|
|
pub operation: String,
|
|
pub input_hash: String,
|
|
pub output_hash: String,
|
|
pub toolbox_version: String,
|
|
pub signature: String,
|
|
}
|
|
|
|
pub fn log_operation(operation: &str, input: &[u8], output: &[u8]) -> Result<(), CliError> {
|
|
let log = AuditLog {
|
|
timestamp: SystemTime::now().duration_since(UNIX_EPOCH)
|
|
.map_err(|e| CliError::Other(e.to_string()))?.as_secs(),
|
|
operator: "0x1234...".to_string(), // 模拟
|
|
operation: operation.to_string(),
|
|
input_hash: format!("0x{:x}", md5::compute(input)),
|
|
output_hash: format!("0x{:x}", md5::compute(output)),
|
|
toolbox_version: "2.0.0".to_string(),
|
|
signature: "0xabcd...".to_string(), // 模拟
|
|
};
|
|
|
|
// 写入审计日志
|
|
let log_json = serde_json::to_string_pretty(&log)
|
|
.map_err(|e| CliError::Other(e.to_string()))?;
|
|
|
|
println!("📝 审计日志已记录:");
|
|
println!("{}", log_json);
|
|
|
|
Ok(())
|
|
}
|