Skip to main content

zerodds_web/
session.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! `SessionId` Authentifizierte Session — Spec §7.3.1.1.
5
6use alloc::string::String;
7
8/// Spec §7.3.1.1 — Authenticated SessionToken (returned by Root::
9/// `create_application` als `authenticatedSessionRepresentation`).
10///
11/// Spec sagt: "The purpose of the SessionId type is to remember an
12/// authenticated client across subsequent invocations of operations on
13/// the service."
14#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15pub struct SessionId(pub String);
16
17impl SessionId {
18    /// Konstruktor.
19    #[must_use]
20    pub fn new(token: impl Into<String>) -> Self {
21        Self(token.into())
22    }
23
24    /// Liefert den Token-String.
25    #[must_use]
26    pub fn as_str(&self) -> &str {
27        &self.0
28    }
29
30    /// `true` wenn der Token nicht leer ist.
31    #[must_use]
32    pub fn is_valid(&self) -> bool {
33        !self.0.is_empty()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn session_id_carries_token_string() {
43        let s = SessionId::new("abc123");
44        assert_eq!(s.as_str(), "abc123");
45        assert!(s.is_valid());
46    }
47
48    #[test]
49    fn empty_session_id_is_invalid() {
50        let s = SessionId::new("");
51        assert!(!s.is_valid());
52    }
53}