pub struct IdentityRegistry { /* private fields */ }Expand description
TOFU Identity Registry
Maintains a mapping of node IDs to their public keys, implementing Trust On First Use semantics.
Implementations§
Source§impl IdentityRegistry
impl IdentityRegistry
Sourcepub const DEFAULT_MAX_IDENTITIES: usize = 256
pub const DEFAULT_MAX_IDENTITIES: usize = 256
Default maximum identities (suitable for most deployments)
Sourcepub fn with_capacity(max_identities: usize) -> Self
pub fn with_capacity(max_identities: usize) -> Self
Create a registry with custom capacity limit
Sourcepub fn verify_or_register(
&mut self,
attestation: &IdentityAttestation,
) -> RegistryResult
pub fn verify_or_register( &mut self, attestation: &IdentityAttestation, ) -> RegistryResult
Verify an identity attestation or register it if new
This is the main TOFU operation:
- Verify the attestation signature
- If node_id is new, register the public key
- If node_id is known, verify the public key matches
Sourcepub fn verify_or_register_at(
&mut self,
attestation: &IdentityAttestation,
now_ms: u64,
) -> RegistryResult
pub fn verify_or_register_at( &mut self, attestation: &IdentityAttestation, now_ms: u64, ) -> RegistryResult
Verify or register with explicit timestamp (for testing)
Sourcepub fn is_known(&self, node_id: NodeId) -> bool
pub fn is_known(&self, node_id: NodeId) -> bool
Check if a node_id is known without modifying the registry
Sourcepub fn get_public_key(&self, node_id: NodeId) -> Option<&[u8; 32]>
pub fn get_public_key(&self, node_id: NodeId) -> Option<&[u8; 32]>
Get the public key for a known node
Sourcepub fn get_record(&self, node_id: NodeId) -> Option<&IdentityRecord>
pub fn get_record(&self, node_id: NodeId) -> Option<&IdentityRecord>
Get the full identity record for a node
Sourcepub fn remove(&mut self, node_id: NodeId) -> Option<IdentityRecord>
pub fn remove(&mut self, node_id: NodeId) -> Option<IdentityRecord>
Remove an identity from the registry
Use with caution - this allows re-registration with a different key.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all known identities
Use with extreme caution - this resets all TOFU trust.
Sourcepub fn known_nodes(&self) -> Vec<NodeId>
pub fn known_nodes(&self) -> Vec<NodeId>
Get all known node IDs
Sourcepub fn pre_register(
&mut self,
node_id: NodeId,
public_key: [u8; 32],
now_ms: u64,
)
pub fn pre_register( &mut self, node_id: NodeId, public_key: [u8; 32], now_ms: u64, )
Pre-register a known identity (for out-of-band key exchange)
This allows registering an identity without an attestation, useful when keys are exchanged through a secure side channel.
Sourcepub fn register_member(
&mut self,
token: &MembershipToken,
authority_public_key: &[u8; 32],
now_ms: u64,
) -> Result<NodeId, RegistryResult>
pub fn register_member( &mut self, token: &MembershipToken, authority_public_key: &[u8; 32], now_ms: u64, ) -> Result<NodeId, RegistryResult>
Register a member via MembershipToken
Validates the token signature and stores the callsign binding. Returns the NodeId for the registered member.
§Arguments
token- The membership token to registerauthority_public_key- The mesh authority’s public key for verificationnow_ms- Current time for expiration checking
§Returns
Ok(NodeId)- The node was registered successfullyErr(RegistryResult)- Registration failed (invalid signature or key mismatch)
Sourcepub fn get_callsign(&self, node_id: NodeId) -> Option<&str>
pub fn get_callsign(&self, node_id: NodeId) -> Option<&str>
Get the callsign for a known node
Sourcepub fn find_by_callsign(&self, callsign: &str) -> Option<NodeId>
pub fn find_by_callsign(&self, callsign: &str) -> Option<NodeId>
Find a node by callsign
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode registry for persistence
Format v2:
- version (1 byte) = 2
- count (4 bytes)
- Per entry (77 bytes):
- node_id (4 bytes)
- public_key (32 bytes)
- first_seen_ms (8 bytes)
- last_seen_ms (8 bytes)
- verification_count (4 bytes)
- has_callsign (1 byte): 0 = no callsign, 1 = has callsign
- callsign (12 bytes, only if has_callsign)
- token_expires_ms (8 bytes, only if has_callsign)
Trait Implementations§
Source§impl Clone for IdentityRegistry
impl Clone for IdentityRegistry
Source§fn clone(&self) -> IdentityRegistry
fn clone(&self) -> IdentityRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more