Skip to main content

rmqtt_codec/
cert.rs

1//! TLS certificate information extracted from MQTT client connections
2//!
3//! This module provides the `CertInfo` struct which holds X.509 certificate
4//! metadata extracted during TLS handshake, including the Common Name,
5//! subject distinguished name, serial number, and organization fields.
6
7use serde::{Deserialize, Serialize};
8use std::fmt;
9
10/// TLS certificate information extracted from peer
11#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
12pub struct CertInfo {
13    /// Common Name from certificate subject
14    pub common_name: Option<String>,
15    /// Full subject distinguished name
16    pub subject: String,
17    /// Certificate serial number
18    pub serial: Option<String>,
19    /// Organization
20    pub organization: Option<String>,
21}
22
23impl CertInfo {
24    /// Creates a new `CertInfo` instance with default (empty) fields
25    pub fn new() -> Self {
26        Self::default()
27    }
28}
29
30impl fmt::Display for CertInfo {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        write!(f, "CN: {:?}, Subject: {}, Org: {:?}", self.common_name, self.subject, self.organization)
33    }
34}