cls_eedi/eebus/pairing.rs
1use ::eebus::runtime::ShipConnection;
2
3use crate::engine::{EngineError, LocalDevice};
4
5/// Record a completed SHIP pairing using identity from the open connection.
6///
7/// Capture [`LocalDevice::trust_revision`] after accepting the trust replacement.
8/// The host drives the SHIP Pairing Service and authenticates the connection.
9/// After the peer supplies its SHIP ID through access methods, pass the same
10/// connection here. The fingerprint and SKI both come from its TLS certificate.
11/// A session without an advertised ID cannot confirm an entry by this method.
12///
13/// Returns `true` for the first confirmation and `false` for an identical repeat.
14/// Persist a changed device checkpoint before publishing trust readback.
15///
16/// ```no_run
17/// # use cls_eedi::{eebus::confirm_pairing, engine::{EngineError, LocalDevice}};
18/// # use eebus::runtime::ShipConnection;
19/// fn on_peer_identified(device: &mut LocalDevice, revision: u64, peer: &ShipConnection)
20/// -> Result<bool, EngineError>
21/// {
22/// confirm_pairing(device, revision, peer)
23/// }
24/// ```
25pub fn confirm_pairing(
26 device: &mut LocalDevice,
27 revision: u64,
28 connection: &ShipConnection,
29) -> Result<bool, EngineError> {
30 if !connection.is_open() {
31 return Err(EngineError::PairingMismatch);
32 }
33 let id = connection
34 .peer_ship_id()
35 .ok_or(EngineError::PairingMismatch)?;
36 device.pairing_established(
37 revision,
38 id,
39 &connection.peer_fingerprint().to_hex(),
40 &connection.peer().to_txt_value(),
41 )
42}