Skip to main content

trust_tasks_https/
handler.rs

1//! The HTTPS-binding [`HttpsHandler`].
2//!
3//! Per SPEC.md §9.2, each transport binding exposes its identity-resolution
4//! and outbound-preparation logic as a [`TransportHandler`]. The HTTPS
5//! handler reports the authenticated peer (from the bearer token, on the
6//! server side; from the configured server VID, on the client side) and
7//! lets the framework apply the §4.8.1 precedence rule unchanged.
8
9use trust_tasks_rs::{TransportContext, TransportHandler};
10
11/// Stable identifier for the HTTPS binding, per SPEC.md §9.2.
12pub const BINDING_URI: &str = "https://trusttasks.org/binding/https/0.2";
13
14/// A [`TransportHandler`] for a single HTTPS exchange.
15///
16/// Constructed per-request on the server (`local` = the server's own VID,
17/// `peer` = the bearer-authenticated sender) and per-instance on the
18/// client (`local` = the client's own VID, `peer` = the configured server
19/// VID).
20///
21/// Either side can be `None`:
22///
23/// * `local = None` — the consumer chooses not to assert its identity to
24///   the framework's audience-binding rules. Allowed for transports that
25///   handle recipient-identity out-of-band.
26/// * `peer = None` — the transport authenticated nothing (no bearer header,
27///   or an unrecognised token). The framework then falls back entirely to
28///   the document's in-band `issuer` plus any `proof` it carries — which,
29///   with no `proof`, means the "issuer" is an unverified string the sender
30///   chose. `HttpsServer` refuses that combination by default; see
31///   `HttpsServerBuilder::require_attribution`.
32#[derive(Debug, Clone)]
33pub struct HttpsHandler {
34    local: Option<String>,
35    peer: Option<String>,
36}
37
38impl HttpsHandler {
39    /// Construct a handler for an exchange where the local party is
40    /// `local` and the transport authenticated `peer` as the counterpart.
41    pub fn new(local: impl Into<Option<String>>, peer: impl Into<Option<String>>) -> Self {
42        Self {
43            local: local.into(),
44            peer: peer.into(),
45        }
46    }
47
48    /// The local party's VID, if configured.
49    pub fn local(&self) -> Option<&str> {
50        self.local.as_deref()
51    }
52
53    /// The authenticated peer's VID, if any.
54    pub fn peer(&self) -> Option<&str> {
55        self.peer.as_deref()
56    }
57}
58
59impl TransportHandler for HttpsHandler {
60    fn binding_uri(&self) -> &str {
61        BINDING_URI
62    }
63
64    fn derive_parties(&self) -> TransportContext {
65        // From the local party's perspective: the transport-authenticated
66        // sender of the document is the *peer*; the transport-authenticated
67        // addressee is the *local* party.
68        TransportContext {
69            issuer: self.peer.clone(),
70            recipient: self.local.clone(),
71        }
72    }
73}