Skip to main content

IdentityRegistry

Struct IdentityRegistry 

Source
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

Source

pub const DEFAULT_MAX_IDENTITIES: usize = 256

Default maximum identities (suitable for most deployments)

Source

pub fn new() -> Self

Create a new empty registry

Source

pub fn with_capacity(max_identities: usize) -> Self

Create a registry with custom capacity limit

Source

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:

  1. Verify the attestation signature
  2. If node_id is new, register the public key
  3. If node_id is known, verify the public key matches
Source

pub fn verify_or_register_at( &mut self, attestation: &IdentityAttestation, now_ms: u64, ) -> RegistryResult

Verify or register with explicit timestamp (for testing)

Source

pub fn is_known(&self, node_id: NodeId) -> bool

Check if a node_id is known without modifying the registry

Source

pub fn get_public_key(&self, node_id: NodeId) -> Option<&[u8; 32]>

Get the public key for a known node

Source

pub fn get_record(&self, node_id: NodeId) -> Option<&IdentityRecord>

Get the full identity record for a node

Source

pub fn len(&self) -> usize

Get the number of known identities

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty

Source

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.

Source

pub fn clear(&mut self)

Clear all known identities

Use with extreme caution - this resets all TOFU trust.

Source

pub fn known_nodes(&self) -> Vec<NodeId>

Get all known node IDs

Source

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.

Source

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 register
  • authority_public_key - The mesh authority’s public key for verification
  • now_ms - Current time for expiration checking
§Returns
  • Ok(NodeId) - The node was registered successfully
  • Err(RegistryResult) - Registration failed (invalid signature or key mismatch)
Source

pub fn get_callsign(&self, node_id: NodeId) -> Option<&str>

Get the callsign for a known node

Source

pub fn find_by_callsign(&self, callsign: &str) -> Option<NodeId>

Find a node by callsign

Source

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)
Source

pub fn decode(data: &[u8]) -> Option<Self>

Decode registry from bytes (supports v1 and v2 formats)

Trait Implementations§

Source§

impl Clone for IdentityRegistry

Source§

fn clone(&self) -> IdentityRegistry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IdentityRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IdentityRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.