Skip to main content

EncryptionManager

Struct EncryptionManager 

Source
pub struct EncryptionManager { /* private fields */ }
Expand description

Encryption manager for secure communications

Manages encryption keys and secure channels:

  • Peer-to-peer session keys via X25519 key exchange
  • Cell group keys for broadcast encryption
  • Device key for at-rest encryption

Implementations§

Source§

impl EncryptionManager

Source

pub fn new(keypair: EncryptionKeypair, device_id: DeviceId) -> Self

Create new encryption manager

Source

pub fn public_key(&self) -> &PublicKey

Get this device’s public key

Source

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

Get this device’s public key bytes

Source

pub async fn establish_channel( &self, peer_id: DeviceId, peer_public_key: &[u8; 32], ) -> Result<(), SecurityError>

Establish secure channel with peer via X25519 key exchange

Source

pub async fn get_channel(&self, peer_id: &DeviceId) -> Option<SecureChannel>

Get secure channel for peer

Source

pub async fn has_channel(&self, peer_id: &DeviceId) -> bool

Check if channel exists for peer

Source

pub async fn remove_channel(&self, peer_id: &DeviceId)

Remove channel (peer disconnected)

Source

pub async fn encrypt_for_peer( &self, peer_id: &DeviceId, plaintext: &[u8], ) -> Result<EncryptedData, SecurityError>

Encrypt message for specific peer

Source

pub async fn decrypt_from_peer( &self, peer_id: &DeviceId, encrypted: &EncryptedData, ) -> Result<Vec<u8>, SecurityError>

Decrypt message from peer

Source

pub async fn get_or_create_cell_key(&self, cell_id: &str) -> GroupKey

Create or get group key for cell

Source

pub async fn set_cell_key(&self, key: GroupKey)

Set cell key (received from leader)

Source

pub async fn get_cell_key(&self, cell_id: &str) -> Option<GroupKey>

Get cell key

Source

pub async fn rotate_cell_key( &self, cell_id: &str, ) -> Result<GroupKey, SecurityError>

Rotate cell key (when member leaves)

Source

pub async fn remove_cell_key(&self, cell_id: &str)

Remove cell key (left cell)

Source

pub async fn encrypt_for_cell( &self, cell_id: &str, plaintext: &[u8], ) -> Result<EncryptedCellMessage, SecurityError>

Encrypt message for cell broadcast

Source

pub async fn decrypt_cell_message( &self, message: &EncryptedCellMessage, ) -> Result<Vec<u8>, SecurityError>

Decrypt cell message

Source

pub fn encrypt_document( &self, plaintext: &[u8], ) -> Result<EncryptedDocument, SecurityError>

Encrypt document for at-rest storage

Source

pub fn decrypt_document( &self, document: &EncryptedDocument, ) -> Result<Vec<u8>, SecurityError>

Decrypt document from storage

Source

pub async fn peer_channel_count(&self) -> usize

Get number of active peer channels

Source

pub async fn cell_key_count(&self) -> usize

Get number of cell keys

Trait Implementations§

Source§

impl Debug for EncryptionManager

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more