File size: 1,026 Bytes
b90fa8e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | use crate::types::{BehavioralTelemetry, PolicyAssertion, TrustState};
pub struct BehavioralTrustEngine {
anomaly_threshold: f32,
}
impl BehavioralTrustEngine {
pub fn new(anomaly_threshold: f32) -> Self {
Self { anomaly_threshold }
}
pub fn process_telemetry(
&self,
session_id: &str,
telemetry: BehavioralTelemetry,
current_state: TrustState,
) -> PolicyAssertion {
let inferred_state = if telemetry.anomaly_score >= self.anomaly_threshold {
TrustState::Compromised
} else if telemetry.anomaly_score < 0.20 && current_state == TrustState::DeviceAuthenticated
{
TrustState::BehavioralContinuity
} else {
current_state
};
PolicyAssertion {
session_id: session_id.to_string(),
asserted_state: inferred_state,
telemetry_proof: telemetry,
timestamp: chrono::Utc::now().timestamp(),
}
}
}
|