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
impl EncryptionManager
Sourcepub fn new(keypair: EncryptionKeypair, device_id: DeviceId) -> Self
pub fn new(keypair: EncryptionKeypair, device_id: DeviceId) -> Self
Create new encryption manager
Sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Get this device’s public key
Sourcepub fn public_key_bytes(&self) -> [u8; 32]
pub fn public_key_bytes(&self) -> [u8; 32]
Get this device’s public key bytes
Sourcepub async fn establish_channel(
&self,
peer_id: DeviceId,
peer_public_key: &[u8; 32],
) -> Result<(), SecurityError>
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
Sourcepub async fn get_channel(&self, peer_id: &DeviceId) -> Option<SecureChannel>
pub async fn get_channel(&self, peer_id: &DeviceId) -> Option<SecureChannel>
Get secure channel for peer
Sourcepub async fn has_channel(&self, peer_id: &DeviceId) -> bool
pub async fn has_channel(&self, peer_id: &DeviceId) -> bool
Check if channel exists for peer
Sourcepub async fn remove_channel(&self, peer_id: &DeviceId)
pub async fn remove_channel(&self, peer_id: &DeviceId)
Remove channel (peer disconnected)
Sourcepub async fn encrypt_for_peer(
&self,
peer_id: &DeviceId,
plaintext: &[u8],
) -> Result<EncryptedData, SecurityError>
pub async fn encrypt_for_peer( &self, peer_id: &DeviceId, plaintext: &[u8], ) -> Result<EncryptedData, SecurityError>
Encrypt message for specific peer
Sourcepub async fn decrypt_from_peer(
&self,
peer_id: &DeviceId,
encrypted: &EncryptedData,
) -> Result<Vec<u8>, SecurityError>
pub async fn decrypt_from_peer( &self, peer_id: &DeviceId, encrypted: &EncryptedData, ) -> Result<Vec<u8>, SecurityError>
Decrypt message from peer
Sourcepub async fn get_or_create_cell_key(&self, cell_id: &str) -> GroupKey
pub async fn get_or_create_cell_key(&self, cell_id: &str) -> GroupKey
Create or get group key for cell
Sourcepub async fn set_cell_key(&self, key: GroupKey)
pub async fn set_cell_key(&self, key: GroupKey)
Set cell key (received from leader)
Sourcepub async fn get_cell_key(&self, cell_id: &str) -> Option<GroupKey>
pub async fn get_cell_key(&self, cell_id: &str) -> Option<GroupKey>
Get cell key
Sourcepub async fn rotate_cell_key(
&self,
cell_id: &str,
) -> Result<GroupKey, SecurityError>
pub async fn rotate_cell_key( &self, cell_id: &str, ) -> Result<GroupKey, SecurityError>
Rotate cell key (when member leaves)
Sourcepub async fn remove_cell_key(&self, cell_id: &str)
pub async fn remove_cell_key(&self, cell_id: &str)
Remove cell key (left cell)
Sourcepub async fn encrypt_for_cell(
&self,
cell_id: &str,
plaintext: &[u8],
) -> Result<EncryptedCellMessage, SecurityError>
pub async fn encrypt_for_cell( &self, cell_id: &str, plaintext: &[u8], ) -> Result<EncryptedCellMessage, SecurityError>
Encrypt message for cell broadcast
Sourcepub async fn decrypt_cell_message(
&self,
message: &EncryptedCellMessage,
) -> Result<Vec<u8>, SecurityError>
pub async fn decrypt_cell_message( &self, message: &EncryptedCellMessage, ) -> Result<Vec<u8>, SecurityError>
Decrypt cell message
Sourcepub fn encrypt_document(
&self,
plaintext: &[u8],
) -> Result<EncryptedDocument, SecurityError>
pub fn encrypt_document( &self, plaintext: &[u8], ) -> Result<EncryptedDocument, SecurityError>
Encrypt document for at-rest storage
Sourcepub fn decrypt_document(
&self,
document: &EncryptedDocument,
) -> Result<Vec<u8>, SecurityError>
pub fn decrypt_document( &self, document: &EncryptedDocument, ) -> Result<Vec<u8>, SecurityError>
Decrypt document from storage
Sourcepub async fn peer_channel_count(&self) -> usize
pub async fn peer_channel_count(&self) -> usize
Get number of active peer channels
Sourcepub async fn cell_key_count(&self) -> usize
pub async fn cell_key_count(&self) -> usize
Get number of cell keys
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EncryptionManager
impl !RefUnwindSafe for EncryptionManager
impl Send for EncryptionManager
impl Sync for EncryptionManager
impl Unpin for EncryptionManager
impl UnsafeUnpin for EncryptionManager
impl !UnwindSafe for EncryptionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more