Skip to main content

zerodds_security/
logging.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! Logging-Plugin SPI (OMG DDS-Security 1.1 §8.6).
5//!
6//! Separater Plugin-Slot fuer Security-Events — wichtig fuer Audits,
7//! Pen-Tests, Forensik. Getrennt vom allgemeinen Application-Logging
8//! damit sicherheitskritische Events nicht versehentlich im Debug-Flag
9//! untergehen.
10//!
11//! zerodds-lint: allow no_dyn_in_safe
12//! (Plugin-SPI benötigt `Box<dyn LoggingPlugin>`.)
13
14extern crate alloc;
15
16use alloc::boxed::Box;
17
18/// Severity eines Security-Events (Spec §8.6.3 Tabelle 36).
19#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
20#[repr(u8)]
21pub enum LogLevel {
22    /// Security-Emergency (Auth-Handshake failed, Key-Exchange-Bruch).
23    Emergency = 0,
24    /// Alert.
25    Alert = 1,
26    /// Critical.
27    Critical = 2,
28    /// Error.
29    Error = 3,
30    /// Warning.
31    Warning = 4,
32    /// Notice.
33    Notice = 5,
34    /// Informational.
35    Informational = 6,
36    /// Debug.
37    Debug = 7,
38}
39
40/// Logging-Plugin (Spec §8.6.2.1).
41pub trait LoggingPlugin: Send + Sync {
42    /// Ein Security-Event loggen.
43    ///
44    /// Spec §8.6.2.1.1 `log`. `participant` identifiziert den betroffenen
45    /// Teilnehmer (GUID-bytes, 16 octets). `category` ist ein
46    /// plugin-spezifischer String ("auth.handshake.failed" etc.).
47    fn log(&self, level: LogLevel, participant: [u8; 16], category: &str, message: &str);
48
49    /// Plugin-Class-Id (z.B. "DDS:Logging:DDS_LogTopic" fuer den
50    /// Spec-vorgesehenen LogTopic-Dispatch).
51    fn plugin_class_id(&self) -> &str;
52}
53
54/// Factory-Alias.
55pub type LoggingPluginBox = Box<dyn LoggingPlugin>;
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn log_levels_order_correctly() {
63        assert!(LogLevel::Emergency < LogLevel::Warning);
64        assert!(LogLevel::Debug > LogLevel::Error);
65    }
66}