pub struct MeshEncryptionKey { /* private fields */ }Expand description
Mesh-wide encryption key for HIVE documents
All nodes sharing the same formation secret derive the same key, enabling encrypted communication across the mesh.
Implementations§
Source§impl MeshEncryptionKey
impl MeshEncryptionKey
Derive a mesh encryption key from a shared secret
Uses HKDF-SHA256 with the mesh ID as salt and a fixed info string to derive a unique 256-bit key for this mesh.
§Arguments
mesh_id- The mesh identifier (e.g., “DEMO”, “ALPHA”)secret- 32-byte shared secret known to all mesh participants
§Example
ⓘ
let secret = [0x42u8; 32]; // In practice, a securely shared secret
let key = MeshEncryptionKey::from_shared_secret("DEMO", &secret);Sourcepub fn encrypt(
&self,
plaintext: &[u8],
) -> Result<EncryptedDocument, EncryptionError>
pub fn encrypt( &self, plaintext: &[u8], ) -> Result<EncryptedDocument, EncryptionError>
Encrypt plaintext document bytes
Generates a random 12-byte nonce and encrypts using ChaCha20-Poly1305. The resulting ciphertext includes a 16-byte authentication tag.
§Arguments
plaintext- Raw document bytes to encrypt
§Returns
Ok(EncryptedDocument)- Encrypted document with nonce and ciphertextErr(EncryptionError)- If encryption fails (should not happen in practice)
Sourcepub fn decrypt(
&self,
encrypted: &EncryptedDocument,
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt( &self, encrypted: &EncryptedDocument, ) -> Result<Vec<u8>, EncryptionError>
Sourcepub fn encrypt_to_bytes(
&self,
plaintext: &[u8],
) -> Result<Vec<u8>, EncryptionError>
pub fn encrypt_to_bytes( &self, plaintext: &[u8], ) -> Result<Vec<u8>, EncryptionError>
Encrypt and encode in one step
Convenience method that encrypts plaintext and returns wire-format bytes.
Sourcepub fn decrypt_from_bytes(
&self,
data: &[u8],
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt_from_bytes( &self, data: &[u8], ) -> Result<Vec<u8>, EncryptionError>
Decode and decrypt in one step
Convenience method that decodes wire-format bytes and decrypts.
Trait Implementations§
Source§impl Clone for MeshEncryptionKey
impl Clone for MeshEncryptionKey
Source§fn clone(&self) -> MeshEncryptionKey
fn clone(&self) -> MeshEncryptionKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MeshEncryptionKey
impl RefUnwindSafe for MeshEncryptionKey
impl Send for MeshEncryptionKey
impl Sync for MeshEncryptionKey
impl Unpin for MeshEncryptionKey
impl UnwindSafe for MeshEncryptionKey
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