1use super::*;
4
5pub struct SecurityMonitor {
7 threat_detector: ThreatDetector,
8 anomaly_detector: AnomalyDetector,
9 compliance_monitor: ComplianceMonitor,
10 security_metrics: SecurityMetrics,
11}
12
13pub struct ThreatDetector {
15 threat_signatures: HashMap<String, ThreatSignature>,
16 detection_rules: Vec<DetectionRule>,
17 alert_system: SecurityAlertSystem,
18}
19
20#[derive(Debug, Clone)]
22pub struct ThreatSignature {
23 pub signature_id: String,
24 pub threat_type: ThreatType,
25 pub pattern: Vec<u8>,
26 pub severity: ThreatSeverity,
27 pub description: String,
28}
29
30#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32pub enum ThreatType {
33 MaliciousKey,
34 CompromisedCertificate,
35 WeakAlgorithm,
36 SideChannelAttack,
37 TimingAttack,
38 Custom(String),
39}
40
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43pub enum ThreatSeverity {
44 Low,
45 Medium,
46 High,
47 Critical,
48}
49
50#[derive(Debug, Clone)]
52pub struct DetectionRule {
53 pub rule_id: String,
54 pub rule_type: DetectionRuleType,
55 pub conditions: Vec<DetectionCondition>,
56 pub actions: Vec<DetectionAction>,
57}
58
59#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
61pub enum DetectionRuleType {
62 Signature,
63 Heuristic,
64 Behavioral,
65 Statistical,
66 Custom(String),
67}
68
69#[derive(Debug, Clone)]
71pub struct DetectionCondition {
72 pub condition_id: String,
73 pub field: String,
74 pub operator: ComparisonOperator,
75 pub value: Vec<u8>,
76}
77
78#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
80pub enum ComparisonOperator {
81 Equals,
82 NotEquals,
83 GreaterThan,
84 LessThan,
85 Contains,
86 Matches,
87}
88
89#[derive(Debug, Clone)]
91pub struct DetectionAction {
92 pub action_id: String,
93 pub action_type: DetectionActionType,
94 pub parameters: HashMap<String, Vec<u8>>,
95}
96
97#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
99pub enum DetectionActionType {
100 Alert,
101 Block,
102 Quarantine,
103 Log,
104 Custom(String),
105}
106
107#[derive(Debug, Clone)]
109pub struct EscalationPolicy {
110 pub policy_id: String,
111 pub trigger_conditions: Vec<String>,
112 pub timeout: u64,
113}
114
115pub struct SecurityAlertSystem {
117 alert_types: Vec<SecurityAlertType>,
118 notification_channels: Vec<NotificationChannel>,
119 escalation_policies: Vec<EscalationPolicy>,
120}
121
122#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
124pub enum SecurityAlertType {
125 Threat,
126 Anomaly,
127 Compliance,
128 System,
129 Custom(String),
130}
131
132pub struct AnomalyDetector {
134 detection_algorithms: Vec<AnomalyDetectionAlgorithm>,
135 baseline_models: HashMap<String, BaselineModel>,
136 alert_thresholds: HashMap<String, f64>,
137}
138
139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
141pub enum AnomalyDetectionAlgorithm {
142 Statistical,
143 MachineLearning,
144 DeepLearning,
145 Ensemble,
146 Custom(String),
147}
148
149#[derive(Debug, Clone)]
151pub struct BaselineModel {
152 pub model_id: String,
153 pub model_type: ModelType,
154 pub parameters: Vec<f64>,
155 pub accuracy: f64,
156}
157
158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
160pub enum ModelType {
161 Statistical,
162 NeuralNetwork,
163 DecisionTree,
164 Custom(String),
165}
166
167pub struct ComplianceMonitor {
169 compliance_frameworks: HashMap<String, ComplianceFramework>,
170 audit_trail: AuditTrail,
171 reporting_engine: ComplianceReportingEngine,
172}
173
174#[derive(Debug, Clone)]
176pub struct ComplianceFramework {
177 pub framework_id: String,
178 pub framework_name: String,
179 pub requirements: Vec<ComplianceRequirement>,
180 pub controls: Vec<ComplianceControl>,
181}
182
183#[derive(Debug, Clone)]
185pub struct ComplianceControl {
186 pub control_id: String,
187 pub control_name: String,
188 pub control_type: ControlType,
189 pub implementation_status: ImplementationStatus,
190}
191
192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
194pub enum ControlType {
195 Preventive,
196 Detective,
197 Corrective,
198 Compensating,
199}
200
201#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
203pub enum ImplementationStatus {
204 Implemented,
205 PartiallyImplemented,
206 NotImplemented,
207 NotApplicable,
208}
209
210pub struct AuditTrail {
212 entries: Vec<AuditEntry>,
213 retention_policy: RetentionPolicy,
214}
215
216#[derive(Debug, Clone)]
218pub struct AuditEntry {
219 pub entry_id: String,
220 pub timestamp: u64,
221 pub event_type: EventType,
222 pub user_id: String,
223 pub resource_id: String,
224 pub action: String,
225 pub result: AuditResult,
226}
227
228#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
230pub enum EventType {
231 KeyOperation,
232 SignatureOperation,
233 EncryptionOperation,
234 ProofOperation,
235 SecurityEvent,
236 ComplianceEvent,
237}
238
239#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
241pub enum AuditResult {
242 Success,
243 Failure,
244 Warning,
245 Error,
246}
247
248pub struct ComplianceReportingEngine {
250 report_templates: HashMap<String, ReportTemplate>,
251 scheduling_engine: ReportSchedulingEngine,
252 distribution_engine: ReportDistributionEngine,
253}
254
255#[derive(Debug, Clone)]
257pub struct ReportTemplate {
258 pub template_id: String,
259 pub template_name: String,
260 pub sections: Vec<ReportSection>,
261 pub format: ReportFormat,
262}
263
264#[derive(Debug, Clone)]
266pub struct ReportSection {
267 pub section_id: String,
268 pub section_name: String,
269 pub content_generator: ContentGenerator,
270 pub data_sources: Vec<String>,
271}
272
273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
275pub enum ContentGenerator {
276 Static,
277 Dynamic,
278 Template,
279 Custom(String),
280}
281
282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
284pub enum ReportFormat {
285 PDF,
286 HTML,
287 JSON,
288 XML,
289 CSV,
290 Custom(String),
291}
292
293pub struct ReportSchedulingEngine {
295 schedules: HashMap<String, ReportSchedule>,
296 scheduler: ReportScheduler,
297}
298
299#[derive(Debug, Clone)]
301pub struct ReportSchedule {
302 pub schedule_id: String,
303 pub template_id: String,
304 pub schedule_type: ScheduleType,
305 pub parameters: ScheduleParameters,
306}
307
308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
310pub enum ScheduleType {
311 Daily,
312 Weekly,
313 Monthly,
314 Quarterly,
315 Yearly,
316 OnDemand,
317 Custom(String),
318}
319
320#[derive(Debug, Clone)]
322pub struct ScheduleParameters {
323 pub start_date: u64,
324 pub end_date: Option<u64>,
325 pub frequency: u32,
326 pub recipients: Vec<String>,
327}
328
329pub struct ReportScheduler {
331 scheduler_type: SchedulerType,
332 queue_manager: ReportQueueManager,
333}
334
335#[derive(Debug, Clone, PartialEq)]
337pub enum SchedulerType {
338 Cron,
339 Interval,
340 EventDriven,
341 Custom(String),
342}
343
344pub struct ReportQueueManager {
346 pending_reports: Vec<QueuedReport>,
347 running_reports: Vec<RunningReport>,
348 completed_reports: Vec<CompletedReport>,
349}
350
351#[derive(Debug, Clone)]
353pub struct QueuedReport {
354 pub report_id: String,
355 pub template_id: String,
356 pub queued_at: u64,
357 pub priority: ReportPriority,
358}
359
360#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
362pub enum ReportPriority {
363 Low,
364 Normal,
365 High,
366 Critical,
367}
368
369#[derive(Debug, Clone)]
371pub struct RunningReport {
372 pub report_id: String,
373 pub started_at: u64,
374 pub progress: f64,
375}
376
377#[derive(Debug, Clone)]
379pub struct CompletedReport {
380 pub report_id: String,
381 pub template_id: String,
382 pub started_at: u64,
383 pub completed_at: u64,
384 pub success: bool,
385}
386
387pub struct ReportDistributionEngine {
389 distribution_channels: HashMap<String, DistributionChannel>,
390 delivery_tracker: DeliveryTracker,
391}
392
393#[derive(Debug, Clone)]
395pub struct DistributionChannel {
396 pub channel_id: String,
397 pub channel_type: DistributionChannelType,
398 pub configuration: ChannelConfiguration,
399}
400
401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
403pub enum DistributionChannelType {
404 Email,
405 FTP,
406 SFTP,
407 API,
408 Webhook,
409 Custom(String),
410}
411
412#[derive(Debug, Clone)]
414pub struct ChannelConfiguration {
415 pub endpoint: String,
416 pub authentication: AuthenticationMethod,
417 pub encryption: bool,
418 pub retry_policy: RetryPolicy,
419}
420
421#[derive(Debug, Clone)]
423pub struct RetryPolicy {
424 pub max_attempts: u32,
425 pub backoff_strategy: BackoffStrategy,
426 pub retry_intervals: Vec<u64>,
427}
428
429#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
431pub enum BackoffStrategy {
432 Fixed,
433 Linear,
434 Exponential,
435 Custom(String),
436}
437
438pub struct DeliveryTracker {
440 deliveries: HashMap<String, DeliveryRecord>,
441 status: DeliveryStatus,
442}
443
444#[derive(Debug, Clone)]
446pub struct DeliveryRecord {
447 pub record_id: String,
448 pub report_id: String,
449 pub channel_id: String,
450 pub attempts: Vec<DeliveryAttempt>,
451 pub final_status: DeliveryFinalStatus,
452}
453
454#[derive(Debug, Clone)]
456pub struct DeliveryAttempt {
457 pub attempt_number: u32,
458 pub timestamp: u64,
459 pub success: bool,
460 pub error_message: Option<String>,
461}
462
463#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
465pub enum DeliveryFinalStatus {
466 Delivered,
467 Failed,
468 Pending,
469 Cancelled,
470}
471
472#[derive(Debug, Clone)]
474pub struct DeliveryStatus {
475 pub total_deliveries: u64,
476 pub successful_deliveries: u64,
477 pub failed_deliveries: u64,
478 pub pending_deliveries: u64,
479}
480
481#[derive(Debug, Clone)]
483pub struct SecurityMetrics {
484 pub threat_metrics: ThreatMetrics,
485 pub anomaly_metrics: AnomalyMetrics,
486 pub compliance_metrics: ComplianceMetrics,
487 pub performance_metrics: SecurityPerformanceMetrics,
488}
489
490#[derive(Debug, Clone)]
492pub struct ThreatMetrics {
493 pub threats_detected: u64,
494 pub threats_blocked: u64,
495 pub false_positives: u64,
496 pub detection_rate: f64,
497 pub response_time: f64,
498}
499
500#[derive(Debug, Clone)]
502pub struct AnomalyMetrics {
503 pub anomalies_detected: u64,
504 pub anomalies_investigated: u64,
505 pub confirmed_anomalies: u64,
506 pub false_positive_rate: f64,
507 pub detection_accuracy: f64,
508}
509
510#[derive(Debug, Clone)]
512pub struct ComplianceMetrics {
513 pub compliance_score: f64,
514 pub controls_implemented: u64,
515 pub controls_passed: u64,
516 pub audit_findings: u64,
517 pub remediation_rate: f64,
518}
519
520#[derive(Debug, Clone)]
522pub struct SecurityPerformanceMetrics {
523 pub average_response_time: f64,
524 pub throughput: f64,
525 pub resource_utilization: f64,
526 pub error_rate: f64,
527}
528impl SecurityMonitor {
529 pub fn new() -> Self {
530 Self {
531 threat_detector: ThreatDetector::new(),
532 anomaly_detector: AnomalyDetector::new(),
533 compliance_monitor: ComplianceMonitor::new(),
534 security_metrics: SecurityMetrics::new(),
535 }
536 }
537
538 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
539 self.threat_detector.initialize()?;
540 self.anomaly_detector.initialize()?;
541 self.compliance_monitor.initialize()?;
542 Ok(())
543 }
544
545 pub fn get_metrics(&self) -> SecurityMetrics {
546 self.security_metrics.clone()
547 }
548}
549
550impl ThreatDetector {
551 pub fn new() -> Self {
552 Self {
553 threat_signatures: HashMap::new(),
554 detection_rules: Vec::new(),
555 alert_system: SecurityAlertSystem::new(),
556 }
557 }
558
559 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
560 self.alert_system.initialize()?;
561 Ok(())
562 }
563
564 pub fn add_threat_signature(&mut self, signature: ThreatSignature) {
566 self.threat_signatures
567 .insert(signature.signature_id.clone(), signature);
568 }
569
570 pub fn get_threat_signature(&self, signature_id: &str) -> Option<&ThreatSignature> {
572 self.threat_signatures.get(signature_id)
573 }
574
575 pub fn list_threat_signatures(&self) -> impl Iterator<Item = &ThreatSignature> {
577 self.threat_signatures.values()
578 }
579
580 pub fn add_detection_rule(&mut self, rule: DetectionRule) {
582 self.detection_rules.push(rule);
583 }
584
585 pub fn list_detection_rules(&self) -> impl Iterator<Item = &DetectionRule> {
587 self.detection_rules.iter()
588 }
589}
590
591impl SecurityAlertSystem {
592 pub fn new() -> Self {
593 Self {
594 alert_types: vec![SecurityAlertType::Threat, SecurityAlertType::Anomaly],
595 notification_channels: vec![NotificationChannel::Email],
596 escalation_policies: Vec::new(),
597 }
598 }
599
600 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
601 Ok(())
602 }
603
604 pub fn alert_types(&self) -> &[SecurityAlertType] {
606 &self.alert_types
607 }
608
609 pub fn add_alert_type(&mut self, alert_type: SecurityAlertType) {
611 if !self.alert_types.contains(&alert_type) {
612 self.alert_types.push(alert_type);
613 }
614 }
615
616 pub fn notification_channels(&self) -> &[NotificationChannel] {
618 &self.notification_channels
619 }
620
621 pub fn add_notification_channel(&mut self, channel: NotificationChannel) {
623 if !self.notification_channels.contains(&channel) {
624 self.notification_channels.push(channel);
625 }
626 }
627
628 pub fn add_escalation_policy(&mut self, policy: EscalationPolicy) {
630 self.escalation_policies.push(policy);
631 }
632
633 pub fn list_escalation_policies(&self) -> impl Iterator<Item = &EscalationPolicy> {
635 self.escalation_policies.iter()
636 }
637}
638
639impl AnomalyDetector {
640 pub fn new() -> Self {
641 Self {
642 detection_algorithms: vec![AnomalyDetectionAlgorithm::Statistical],
643 baseline_models: HashMap::new(),
644 alert_thresholds: HashMap::new(),
645 }
646 }
647
648 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
649 Ok(())
650 }
651
652 pub fn detection_algorithms(&self) -> &[AnomalyDetectionAlgorithm] {
654 &self.detection_algorithms
655 }
656
657 pub fn add_detection_algorithm(&mut self, algorithm: AnomalyDetectionAlgorithm) {
659 if !self.detection_algorithms.contains(&algorithm) {
660 self.detection_algorithms.push(algorithm);
661 }
662 }
663
664 pub fn add_baseline_model(&mut self, model: BaselineModel) {
666 self.baseline_models.insert(model.model_id.clone(), model);
667 }
668
669 pub fn get_baseline_model(&self, model_id: &str) -> Option<&BaselineModel> {
671 self.baseline_models.get(model_id)
672 }
673
674 pub fn list_baseline_models(&self) -> impl Iterator<Item = &BaselineModel> {
676 self.baseline_models.values()
677 }
678
679 pub fn set_alert_threshold(&mut self, metric: String, threshold: f64) {
681 self.alert_thresholds.insert(metric, threshold);
682 }
683
684 pub fn get_alert_threshold(&self, metric: &str) -> Option<f64> {
686 self.alert_thresholds.get(metric).copied()
687 }
688}
689
690impl ComplianceMonitor {
691 pub fn new() -> Self {
692 Self {
693 compliance_frameworks: HashMap::new(),
694 audit_trail: AuditTrail::new(),
695 reporting_engine: ComplianceReportingEngine::new(),
696 }
697 }
698
699 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
700 self.reporting_engine.initialize()?;
701 Ok(())
702 }
703
704 pub fn add_compliance_framework(&mut self, framework: ComplianceFramework) {
706 self.compliance_frameworks
707 .insert(framework.framework_id.clone(), framework);
708 }
709
710 pub fn get_compliance_framework(&self, framework_id: &str) -> Option<&ComplianceFramework> {
712 self.compliance_frameworks.get(framework_id)
713 }
714
715 pub fn list_compliance_frameworks(&self) -> impl Iterator<Item = &ComplianceFramework> {
717 self.compliance_frameworks.values()
718 }
719
720 pub fn audit_trail(&self) -> &AuditTrail {
722 &self.audit_trail
723 }
724
725 pub fn audit_trail_mut(&mut self) -> &mut AuditTrail {
727 &mut self.audit_trail
728 }
729}
730
731impl AuditTrail {
732 pub fn new() -> Self {
733 Self {
734 entries: Vec::new(),
735 retention_policy: RetentionPolicy {
736 retention_days: 2555, auto_delete: false,
738 archive_before_delete: true,
739 },
740 }
741 }
742
743 pub fn add_entry(&mut self, entry: AuditEntry) {
745 let cutoff = entry
746 .timestamp
747 .saturating_sub((self.retention_policy.retention_days as u64) * 86400);
748 self.entries.retain(|e| e.timestamp >= cutoff);
749 self.entries.push(entry);
750 }
751
752 pub fn entry_count(&self) -> usize {
754 self.entries.len()
755 }
756
757 pub fn entries(&self) -> &[AuditEntry] {
759 &self.entries
760 }
761
762 pub fn retention_policy(&self) -> &RetentionPolicy {
764 &self.retention_policy
765 }
766}
767
768impl ComplianceReportingEngine {
769 pub fn new() -> Self {
770 Self {
771 report_templates: HashMap::new(),
772 scheduling_engine: ReportSchedulingEngine::new(),
773 distribution_engine: ReportDistributionEngine::new(),
774 }
775 }
776
777 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
778 self.scheduling_engine.initialize()?;
779 self.distribution_engine.initialize()?;
780 Ok(())
781 }
782
783 pub fn add_report_template(&mut self, template: ReportTemplate) {
785 self.report_templates
786 .insert(template.template_id.clone(), template);
787 }
788
789 pub fn get_report_template(&self, template_id: &str) -> Option<&ReportTemplate> {
791 self.report_templates.get(template_id)
792 }
793
794 pub fn list_report_templates(&self) -> impl Iterator<Item = &ReportTemplate> {
796 self.report_templates.values()
797 }
798}
799
800impl ReportSchedulingEngine {
801 pub fn new() -> Self {
802 Self {
803 schedules: HashMap::new(),
804 scheduler: ReportScheduler::new(),
805 }
806 }
807
808 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
809 Ok(())
810 }
811
812 pub fn add_schedule(&mut self, schedule: ReportSchedule) {
814 self.schedules
815 .insert(schedule.schedule_id.clone(), schedule);
816 }
817
818 pub fn get_schedule(&self, schedule_id: &str) -> Option<&ReportSchedule> {
820 self.schedules.get(schedule_id)
821 }
822
823 pub fn list_schedules(&self) -> impl Iterator<Item = &ReportSchedule> {
825 self.schedules.values()
826 }
827
828 pub fn scheduler(&self) -> &ReportScheduler {
830 &self.scheduler
831 }
832
833 pub fn scheduler_mut(&mut self) -> &mut ReportScheduler {
835 &mut self.scheduler
836 }
837}
838
839impl ReportScheduler {
840 pub fn new() -> Self {
841 Self {
842 scheduler_type: SchedulerType::Cron,
843 queue_manager: ReportQueueManager::new(),
844 }
845 }
846
847 pub fn scheduler_type(&self) -> &SchedulerType {
849 &self.scheduler_type
850 }
851
852 pub fn set_scheduler_type(&mut self, scheduler_type: SchedulerType) {
854 self.scheduler_type = scheduler_type;
855 }
856
857 pub fn queue_manager(&self) -> &ReportQueueManager {
859 &self.queue_manager
860 }
861
862 pub fn queue_manager_mut(&mut self) -> &mut ReportQueueManager {
864 &mut self.queue_manager
865 }
866}
867
868impl ReportQueueManager {
869 pub fn new() -> Self {
870 Self {
871 pending_reports: Vec::new(),
872 running_reports: Vec::new(),
873 completed_reports: Vec::new(),
874 }
875 }
876
877 pub fn enqueue_report(&mut self, report: QueuedReport) {
879 self.pending_reports.push(report);
880 }
881
882 pub fn start_next_report(&mut self) -> Option<QueuedReport> {
884 if self.pending_reports.is_empty() {
885 None
886 } else {
887 let report = self.pending_reports.remove(0);
888 self.running_reports.push(RunningReport {
889 report_id: report.report_id.clone(),
890 started_at: std::time::SystemTime::now()
891 .duration_since(std::time::UNIX_EPOCH)
892 .unwrap_or_default()
893 .as_secs(),
894 progress: 0.0,
895 });
896 Some(report)
897 }
898 }
899
900 pub fn complete_report(&mut self, report: CompletedReport) {
902 self.running_reports
903 .retain(|r| r.report_id != report.report_id);
904 self.completed_reports.push(report);
905 }
906
907 pub fn pending_count(&self) -> usize {
909 self.pending_reports.len()
910 }
911
912 pub fn running_count(&self) -> usize {
914 self.running_reports.len()
915 }
916
917 pub fn completed_count(&self) -> usize {
919 self.completed_reports.len()
920 }
921}
922
923impl ReportDistributionEngine {
924 pub fn new() -> Self {
925 Self {
926 distribution_channels: HashMap::new(),
927 delivery_tracker: DeliveryTracker::new(),
928 }
929 }
930
931 pub fn initialize(&mut self) -> Result<(), CryptographicError> {
932 Ok(())
933 }
934
935 pub fn add_distribution_channel(&mut self, channel: DistributionChannel) {
937 self.distribution_channels
938 .insert(channel.channel_id.clone(), channel);
939 }
940
941 pub fn get_distribution_channel(&self, channel_id: &str) -> Option<&DistributionChannel> {
943 self.distribution_channels.get(channel_id)
944 }
945
946 pub fn list_distribution_channels(&self) -> impl Iterator<Item = &DistributionChannel> {
948 self.distribution_channels.values()
949 }
950
951 pub fn delivery_tracker(&self) -> &DeliveryTracker {
953 &self.delivery_tracker
954 }
955
956 pub fn delivery_tracker_mut(&mut self) -> &mut DeliveryTracker {
958 &mut self.delivery_tracker
959 }
960}
961
962impl DeliveryTracker {
963 pub fn new() -> Self {
964 Self {
965 deliveries: HashMap::new(),
966 status: DeliveryStatus {
967 total_deliveries: 0,
968 successful_deliveries: 0,
969 failed_deliveries: 0,
970 pending_deliveries: 0,
971 },
972 }
973 }
974
975 pub fn record_delivery(&mut self, record: DeliveryRecord) {
977 self.status.total_deliveries += 1;
978 match record.final_status {
979 DeliveryFinalStatus::Delivered => self.status.successful_deliveries += 1,
980 DeliveryFinalStatus::Failed => self.status.failed_deliveries += 1,
981 DeliveryFinalStatus::Pending | DeliveryFinalStatus::Cancelled => {
982 self.status.pending_deliveries += 1;
983 }
984 }
985 self.deliveries.insert(record.record_id.clone(), record);
986 }
987
988 pub fn get_delivery(&self, record_id: &str) -> Option<&DeliveryRecord> {
990 self.deliveries.get(record_id)
991 }
992
993 pub fn list_deliveries(&self) -> impl Iterator<Item = &DeliveryRecord> {
995 self.deliveries.values()
996 }
997
998 pub fn status(&self) -> &DeliveryStatus {
1000 &self.status
1001 }
1002}
1003
1004impl DeliveryStatus {
1005 pub fn new() -> Self {
1006 Self {
1007 total_deliveries: 0,
1008 successful_deliveries: 0,
1009 failed_deliveries: 0,
1010 pending_deliveries: 0,
1011 }
1012 }
1013}
1014
1015impl SecurityMetrics {
1016 pub fn new() -> Self {
1017 Self {
1018 threat_metrics: ThreatMetrics::new(),
1019 anomaly_metrics: AnomalyMetrics::new(),
1020 compliance_metrics: ComplianceMetrics::new(),
1021 performance_metrics: SecurityPerformanceMetrics::new(),
1022 }
1023 }
1024
1025 pub fn get_metrics(&self) -> SecurityMetrics {
1026 self.clone()
1027 }
1028}
1029
1030impl ThreatMetrics {
1031 pub fn new() -> Self {
1032 Self {
1033 threats_detected: 0,
1034 threats_blocked: 0,
1035 false_positives: 0,
1036 detection_rate: 0.0,
1037 response_time: 0.0,
1038 }
1039 }
1040}
1041
1042impl AnomalyMetrics {
1043 pub fn new() -> Self {
1044 Self {
1045 anomalies_detected: 0,
1046 anomalies_investigated: 0,
1047 confirmed_anomalies: 0,
1048 false_positive_rate: 0.0,
1049 detection_accuracy: 0.0,
1050 }
1051 }
1052}
1053
1054impl ComplianceMetrics {
1055 pub fn new() -> Self {
1056 Self {
1057 compliance_score: 1.0,
1058 controls_implemented: 0,
1059 controls_passed: 0,
1060 audit_findings: 0,
1061 remediation_rate: 0.0,
1062 }
1063 }
1064}
1065
1066impl SecurityPerformanceMetrics {
1067 pub fn new() -> Self {
1068 Self {
1069 average_response_time: 0.0,
1070 throughput: 0.0,
1071 resource_utilization: 0.0,
1072 error_rate: 0.0,
1073 }
1074 }
1075}