Skip to main content

tf_types/
bridges.rs

1//! Common compatibility-bridge framework. Concrete bridges live in
2//! sibling modules (e.g. `bridge_spiffe`) and register themselves with a
3//! `BridgeRegistry` so higher-level code can look up a bridge by kind at
4//! runtime.
5
6use std::sync::Arc;
7
8#[derive(Clone, Debug, PartialEq, Eq)]
9pub enum BridgeKind {
10    Spiffe,
11    Webauthn,
12    Mcp,
13    Oauth,
14    Gnap,
15    Tls,
16    Did,
17    Matrix,
18    Webhook,
19    Grpc,
20    ServiceMesh,
21    A2a,
22}
23
24#[derive(Debug, thiserror::Error, PartialEq, Eq)]
25pub enum BridgeError {
26    #[error("bridge unsupported: {0}")]
27    Unsupported(String),
28    #[error("bridge invalid input: {0}")]
29    InvalidInput(String),
30    #[error("bridge rejected input: {0}")]
31    Rejected(String),
32    #[error("bridge internal error: {0}")]
33    Internal(String),
34}
35
36pub trait Bridge: Send + Sync {
37    fn bridge_id(&self) -> &str;
38    fn kind(&self) -> BridgeKind;
39    fn trust_domain(&self) -> &str;
40}
41
42#[derive(Default)]
43pub struct BridgeRegistry {
44    bridges: Vec<Arc<dyn Bridge>>,
45}
46
47impl BridgeRegistry {
48    pub fn new() -> Self {
49        BridgeRegistry {
50            bridges: Vec::new(),
51        }
52    }
53
54    pub fn register(&mut self, bridge: Arc<dyn Bridge>) {
55        self.bridges.push(bridge);
56    }
57
58    pub fn get(&self, kind: BridgeKind) -> Option<Arc<dyn Bridge>> {
59        self.bridges.iter().find(|b| b.kind() == kind).cloned()
60    }
61
62    pub fn list(&self) -> &[Arc<dyn Bridge>] {
63        &self.bridges
64    }
65}