PersistedState

Struct PersistedState 

Source
pub struct PersistedState {
    pub version: u32,
    pub persisted_at_ms: u64,
    /* private fields */
}
Expand description

Complete persisted state for a HIVE node.

Contains all security-critical data needed to restore a node after reboot without network access.

Fields§

§version: u32

Format version for migration support

§persisted_at_ms: u64

Timestamp when state was last persisted

Implementations§

Source§

impl PersistedState

Source

pub fn new(identity: &DeviceIdentity, genesis: Option<&MeshGenesis>) -> Self

Create a new persisted state from components.

Source

pub fn with_registry( identity: &DeviceIdentity, genesis: Option<&MeshGenesis>, registry: &IdentityRegistry, ) -> Self

Create persisted state with an existing identity registry.

Source

pub fn restore_identity(&self) -> Result<DeviceIdentity, PersistenceError>

Restore the device identity from persisted state.

Source

pub fn restore_genesis(&self) -> Option<MeshGenesis>

Restore the mesh genesis from persisted state.

Source

pub fn restore_registry(&self) -> IdentityRegistry

Restore the identity registry from persisted state.

Source

pub fn revoked_keys(&self) -> &[[u8; 32]]

Get the list of revoked public keys.

Source

pub fn add_revoked_key(&mut self, public_key: [u8; 32])

Add a revoked public key.

Source

pub fn update_registry(&mut self, registry: &IdentityRegistry)

Update the identity registry data.

Source

pub fn save(&self, storage: &dyn SecureStorage) -> Result<(), PersistenceError>

Save state to secure storage.

The storage key used is “hive_persisted_state”.

Source

pub fn load(storage: &dyn SecureStorage) -> Result<Self, PersistenceError>

Load state from secure storage.

Returns Err(NotFound) if no state has been persisted.

Source

pub fn delete(storage: &dyn SecureStorage) -> Result<(), PersistenceError>

Delete persisted state from storage.

Use with caution - this will require re-provisioning.

Source

pub fn encode(&self) -> Vec<u8>

Encode the state to bytes.

Format:

  • Magic (4 bytes): “HIVE”
  • Version (4 bytes): u32 LE
  • Private key (32 bytes)
  • Persisted at (8 bytes): u64 LE timestamp
  • Genesis length (4 bytes): u32 LE (0 if none)
  • Genesis data (N bytes)
  • Registry length (4 bytes): u32 LE
  • Registry data (N bytes)
  • Revoked count (4 bytes): u32 LE
  • Revoked keys (32 bytes each)
Source

pub fn decode(data: &[u8]) -> Result<Self, PersistenceError>

Decode state from bytes.

Source

pub fn set_persisted_at(&mut self, timestamp_ms: u64)

Set the persistence timestamp.

Trait Implementations§

Source§

impl Clone for PersistedState

Source§

fn clone(&self) -> PersistedState

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 PersistedState

Source§

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

Formats the value using the given formatter. 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.