pub trait Storage:
Send
+ Sync
+ 'static {
// Required methods
fn pairing_psk(&self) -> Result<Option<[u8; 32]>>;
fn store_pairing_psk(&self, psk: &[u8; 32]) -> Result<()>;
fn load_pairings(&self) -> Result<Vec<StoredPsk>>;
fn store_pairing(&self, record: StoredPsk) -> Result<()>;
fn remove_pairing(&self, server_id: &str) -> Result<()>;
}Expand description
The place pairing records and the pairing PSK live.
The host implements this trait - over a file, a database, or the device’s own configuration -
and hands it to the client. Every method may be called from the session task, so an
implementation must be Send + Sync.
The trait is a store, not a policy: store_pairing replaces a record
for the same server and appends the new one, and persist_pairing is what the client calls to
apply the ordering, the capacity of MAX_PAIRINGS and the live-record pin. A backend therefore
never has to know which connection is live.
Required Methods§
Sourcefn pairing_psk(&self) -> Result<Option<[u8; 32]>>
fn pairing_psk(&self) -> Result<Option<[u8; 32]>>
The long-lived pairing PSK the host restored, or None on a device’s first run.
The client draws a key when this is None, hands it back through
store_pairing_psk, and uses it on every connection. The
operator-facing version-0 token is client_key || pairing_psk; the crate has no accessor
that builds it yet, so a host assembles it from the identity’s public key and this value
with syncspin_core::pairing::token::encode_v0. A key the host restored is used as it is, so
pairing survives a restart.
Sourcefn store_pairing_psk(&self, psk: &[u8; 32]) -> Result<()>
fn store_pairing_psk(&self, psk: &[u8; 32]) -> Result<()>
Persists the pairing PSK the client drew on this run.
The client calls this once, when pairing_psk returned None; a
key is never rotated on its own.
Sourcefn load_pairings(&self) -> Result<Vec<StoredPsk>>
fn load_pairings(&self) -> Result<Vec<StoredPsk>>
The records of known servers, oldest first.
A backend may return more than MAX_PAIRINGS records; the client reads them all and never
trims a store it did not write.
Sourcefn store_pairing(&self, record: StoredPsk) -> Result<()>
fn store_pairing(&self, record: StoredPsk) -> Result<()>
Stores record as the newest record for its server.
This is the primitive persist_pairing is built on: a record the store already holds for
the same server_id is replaced and the new one is placed at the end, so storing it again
moves it to the end of the list. A backend need not evict here - capacity and the live-record
pin belong to persist_pairing, which calls this only after it has made room. FileStorage
trims to the floor as a safety net for a direct caller, and cannot pin a live record it does
not know. An empty server_id is rejected, so the store cannot be left holding a record that
can never be selected.
Sourcefn remove_pairing(&self, server_id: &str) -> Result<()>
fn remove_pairing(&self, server_id: &str) -> Result<()>
Removes the record for server_id.
Removing a record the store does not hold is not an error: a server may unpair a client that already forgot it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".