Skip to main content

trust_tasks_tsp/
handler.rs

1//! [`TspHandler`] — the framework's [`TransportHandler`] for the TSP binding.
2//!
3//! Constructed per-exchange by [`unpack_trust_task`](crate::unpack_trust_task)
4//! (one per inbound message). The handler reports the locally-controlled VID as
5//! `recipient` and the TSP-authenticated peer VID as `issuer`, then lets the
6//! framework's default [`TransportHandler::resolve_parties`] apply SPEC §4.8.1
7//! precedence unchanged. Because a TSP VID *is* a framework VID, no
8//! normalisation is applied — comparison is exact string equality.
9
10use trust_tasks_rs::{TransportContext, TransportHandler};
11
12/// Stable identifier for the TSP binding, per SPEC §9.3.
13pub const BINDING_URI: &str = "https://trusttasks.org/binding/tsp/0.1";
14
15/// A [`TransportHandler`] for one TSP exchange.
16///
17/// `local` is the VID this party controls (the `VID_rcvr` it unwrapped the
18/// message for). `peer` is the TSP-authenticated sender VID (`VID_sndr`). Both
19/// are `Option<String>` to satisfy the trait's shape, but for a successfully
20/// unpacked TSP message both are always `Some` — TSP has no unauthenticated
21/// sender mode.
22#[derive(Debug, Clone)]
23pub struct TspHandler {
24    local: Option<String>,
25    peer: Option<String>,
26}
27
28impl TspHandler {
29    /// Construct a handler from the recipient and authenticated-sender VIDs.
30    pub fn new(local: impl Into<Option<String>>, peer: impl Into<Option<String>>) -> Self {
31        Self {
32            local: local.into(),
33            peer: peer.into(),
34        }
35    }
36
37    /// The local party's VID, if set.
38    pub fn local(&self) -> Option<&str> {
39        self.local.as_deref()
40    }
41
42    /// The TSP-authenticated peer VID, if set.
43    pub fn peer(&self) -> Option<&str> {
44        self.peer.as_deref()
45    }
46}
47
48impl TransportHandler for TspHandler {
49    fn binding_uri(&self) -> &str {
50        BINDING_URI
51    }
52
53    fn derive_parties(&self) -> TransportContext {
54        TransportContext {
55            issuer: self.peer.clone(),
56            recipient: self.local.clone(),
57        }
58    }
59}