118 lines
2.9 KiB
Rust
118 lines
2.9 KiB
Rust
//! NAC AI合规系统
|
|
//!
|
|
//! 实现基于AI的七层合规验证体系
|
|
|
|
pub mod compliance_layer;
|
|
pub mod ai_validator;
|
|
pub mod rule_engine;
|
|
pub mod model_manager;
|
|
pub mod report_generator;
|
|
pub mod error;
|
|
|
|
pub use compliance_layer::*;
|
|
pub use ai_validator::*;
|
|
pub use rule_engine::*;
|
|
pub use model_manager::*;
|
|
pub use report_generator::*;
|
|
pub use error::*;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
/// AI合规系统
|
|
pub struct AIComplianceSystem {
|
|
/// AI验证器
|
|
validators: HashMap<ComplianceLayer, Box<dyn AIValidator>>,
|
|
/// 规则引擎
|
|
rule_engine: RuleEngine,
|
|
/// 模型管理器
|
|
model_manager: ModelManager,
|
|
/// 报告生成器
|
|
report_generator: ReportGenerator,
|
|
}
|
|
|
|
impl AIComplianceSystem {
|
|
/// 创建新的AI合规系统
|
|
pub fn new() -> Result<Self> {
|
|
Ok(Self {
|
|
validators: HashMap::new(),
|
|
rule_engine: RuleEngine::new(),
|
|
model_manager: ModelManager::new(),
|
|
report_generator: ReportGenerator::new(),
|
|
})
|
|
}
|
|
|
|
/// 注册验证器
|
|
pub fn register_validator(&mut self, layer: ComplianceLayer, validator: Box<dyn AIValidator>) {
|
|
self.validators.insert(layer, validator);
|
|
}
|
|
|
|
/// 执行合规验证
|
|
pub async fn verify(&self, layer: ComplianceLayer, data: &ComplianceData) -> Result<ComplianceResult> {
|
|
// 获取验证器
|
|
let validator = self.validators.get(&layer)
|
|
.ok_or_else(|| Error::ValidatorNotFound(format!("{:?}", layer)))?;
|
|
|
|
// 执行AI验证
|
|
let mut result = validator.validate(data).await?;
|
|
|
|
// 应用规则引擎
|
|
self.rule_engine.apply(&mut result, data)?;
|
|
|
|
Ok(result)
|
|
}
|
|
|
|
/// 执行全层验证
|
|
pub async fn verify_all(&self, data: &ComplianceData) -> Result<Vec<ComplianceResult>> {
|
|
let mut results = Vec::new();
|
|
|
|
for layer in ComplianceLayer::all() {
|
|
let result = self.verify(layer, data).await?;
|
|
results.push(result);
|
|
}
|
|
|
|
Ok(results)
|
|
}
|
|
|
|
/// 生成合规报告
|
|
pub fn generate_report(&self, results: &[ComplianceResult]) -> Result<ComplianceReport> {
|
|
self.report_generator.generate(results)
|
|
}
|
|
|
|
/// 获取规则引擎
|
|
pub fn rule_engine(&self) -> &RuleEngine {
|
|
&self.rule_engine
|
|
}
|
|
|
|
/// 获取规则引擎(可变)
|
|
pub fn rule_engine_mut(&mut self) -> &mut RuleEngine {
|
|
&mut self.rule_engine
|
|
}
|
|
|
|
/// 获取模型管理器
|
|
pub fn model_manager(&self) -> &ModelManager {
|
|
&self.model_manager
|
|
}
|
|
|
|
/// 获取模型管理器(可变)
|
|
pub fn model_manager_mut(&mut self) -> &mut ModelManager {
|
|
&mut self.model_manager
|
|
}
|
|
}
|
|
|
|
impl Default for AIComplianceSystem {
|
|
fn default() -> Self {
|
|
Self::new().expect("mainnet: handle error")
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_system_creation() {
|
|
let system = AIComplianceSystem::new();
|
|
assert!(system.is_ok());
|
|
}
|
|
}
|