pub struct PacketCipher { /* private fields */ }Expand description
Packet encryptor with automatic nonce management and replay protection
§Performance
- Uses counter-based nonces (no RNG syscalls)
- Caches cipher instance for reuse
- Pre-allocates output buffers with known capacity
Implementations§
Source§impl PacketCipher
impl PacketCipher
Sourcepub fn new(key: DataChannelKey) -> Self
pub fn new(key: DataChannelKey) -> Self
Create a new packet cipher
Sourcepub fn encrypt(&mut self, plaintext: &[u8]) -> Result<Vec<u8>>
pub fn encrypt(&mut self, plaintext: &[u8]) -> Result<Vec<u8>>
Encrypt a packet
Returns: [8-byte packet_id | ciphertext | 16-byte tag]
Sourcepub fn encrypt_into(
&mut self,
plaintext: &[u8],
output: &mut Vec<u8>,
) -> Result<usize>
pub fn encrypt_into( &mut self, plaintext: &[u8], output: &mut Vec<u8>, ) -> Result<usize>
Encrypt a packet into a pre-allocated buffer
Returns the total bytes written (header + ciphertext + tag). Buffer should be cleared before calling.
Sourcepub fn decrypt(&mut self, packet: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&mut self, packet: &[u8]) -> Result<Vec<u8>>
Decrypt a packet with replay protection
Sourcepub fn tx_counter(&self) -> u64
pub fn tx_counter(&self) -> u64
Get current TX counter (for debugging/stats)
Auto Trait Implementations§
impl Freeze for PacketCipher
impl RefUnwindSafe for PacketCipher
impl Send for PacketCipher
impl Sync for PacketCipher
impl Unpin for PacketCipher
impl UnwindSafe for PacketCipher
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