Skip to main content

StreamCipher

Struct StreamCipher 

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

Stream cipher for large file encryption.

Each chunk is independently authenticated, allowing:

  • Constant memory usage regardless of file size
  • Early detection of tampering
  • Potential for parallel processing

Implementations§

Source§

impl StreamCipher

Source

pub fn new(key: [u8; 32]) -> Self

Create a new stream cipher with the given key.

Source

pub fn with_chunk_size(key: [u8; 32], chunk_size: usize) -> Self

Create with custom chunk size.

Source

pub fn chunk_size(&self) -> usize

Get the chunk size.

Source

pub fn encrypt_stream<'a>( &'a self, data: &'a [u8], ) -> Result<StreamEncryptor<'a>>

Encrypt a stream of data.

Returns an iterator over encrypted chunks. First chunk is the header containing stream salt.

Source

pub fn decrypt_stream(&self, encrypted: &[u8]) -> Result<Vec<u8>>

Decrypt a stream of encrypted chunks.

Source

pub fn encrypt(&self, data: &[u8]) -> Result<Vec<u8>>

Encrypt entire data at once (convenience method).

Source

pub fn decrypt(&self, encrypted: &[u8]) -> Result<Vec<u8>>

Decrypt entire data at once (convenience method).

Trait Implementations§

Source§

impl Drop for StreamCipher

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Zeroize for StreamCipher

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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, 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, 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.