Struct wolf_crypto::chacha::Writer

source ·
pub struct Writer<W, const CHUNK: usize> { /* private fields */ }
Available on crate feature std only.
Expand description

A wrapper for any implementor of std::io::Write.

Writer implements std::io::Write and takes a child which also implements this trait. This type can wrap any writer, and ensure all data passed to said writer is encrypted.

Implementations§

source§

impl<W, const CHUNK: usize> Writer<W, CHUNK>

source

pub const fn new(chacha: ChaCha20<Streaming>, writer: W) -> Self

Creates a new Writer instance.

§Arguments
  • chacha - The ChaCha20 instance in streaming mode.
  • writer - The underlying writer.
§Returns

A new Writer instance.

source

pub fn finish(self) -> ChaCha20<NeedsIv>

Finishes the streaming encryption and returns to the NeedsIv state.

§Returns

A ChaCha20 instance in the NeedsIv state.

Methods from Deref<Target = ChaCha20<Streaming>>§

source

pub fn decrypt_into(&mut self, cipher: &[u8], output: &mut [u8]) -> Res

Decrypts the ciphertext into the output buffer.

§Arguments
  • cipher - The ciphertext to decrypt.
  • output - The buffer to store the decrypted data.
§Returns

A Res indicating the success or failure of the operation.

source

pub fn decrypt_into_sized<const I: usize, const O: usize>( &mut self, cipher: &[u8; I], output: &mut [u8; O], ) -> Res

Decrypts the ciphertext into the output buffer with compile-time size checking.

§Type Parameters
  • I - The size of the ciphertext array.
  • O - The size of the output array.
§Arguments
  • cipher - The ciphertext array to decrypt.
  • output - The array to store the decrypted data.
§Returns

A Res indicating the success or failure of the operation.

source

pub fn decrypt_into_exact<const C: usize>( &mut self, cipher: &[u8; C], output: &mut [u8; C], ) -> Res

Decrypts the ciphertext into the output buffer with exact sizes.

§Type Parameters
  • C - The size of both the ciphertext and output arrays.
§Arguments
  • cipher - The ciphertext array to decrypt.
  • output - The array to store the decrypted data.
§Returns

A Res indicating the success or failure of the operation.

source

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

Available on crate feature alloc only.

Decrypts the ciphertext and returns the plaintext as a vector.

§Arguments
  • cipher - The ciphertext to decrypt.
§Returns

A Result containing either the decrypted plaintext as a vector on success, or an Unspecified error on failure.

source

pub fn decrypt_exact<const O: usize>( &mut self, cipher: &[u8; O], ) -> Result<[u8; O], Unspecified>

Decrypts the ciphertext array and returns the plaintext array.

§Type Parameters
  • O - The size of the ciphertext and plaintext arrays.
§Arguments
  • cipher - The ciphertext array to decrypt.
§Returns

A Result containing either the decrypted plaintext array on success, or an Unspecified error on failure.

source

pub fn encrypt_into(&mut self, input: &[u8], output: &mut [u8]) -> Res

Encrypts the input into the output buffer in streaming mode.

§Arguments
  • input - The input to encrypt.
  • output - The buffer to store the encrypted data.
§Returns

A Res indicating the success or failure of the operation.

source

pub fn encrypt_into_sized<const I: usize, const O: usize>( &mut self, input: &[u8; I], output: &mut [u8; O], ) -> Res

Encrypts the input into the output buffer in streaming mode with compile-time size checking.

§Type Parameters
  • I - The size of the input array.
  • O - The size of the output array.
§Arguments
  • input - The input array to encrypt.
  • output - The array to store the encrypted data.
§Returns

A Res indicating the success or failure of the operation.

source

pub fn encrypt_into_exact<const C: usize>( &mut self, input: &[u8; C], output: &mut [u8; C], ) -> Res

Encrypts the input into the output buffer in streaming mode with exact sizes.

§Type Parameters
  • C - The size of both the input and output arrays.
§Arguments
  • input - The input array to encrypt.
  • output - The array to store the encrypted data.
§Returns

A Res indicating the success or failure of the operation.

Trait Implementations§

source§

impl<W, const CHUNK: usize> Deref for Writer<W, CHUNK>

source§

type Target = ChaCha20<Streaming>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<W, const CHUNK: usize> DerefMut for Writer<W, CHUNK>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<W: Write, const CHUNK: usize> Write for Writer<W, CHUNK>

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Encrypts and writes the given buffer.

§Arguments
  • buf - The buffer to encrypt and write.
§Returns

The number of bytes written on success, or an io::Error on failure.

§Note

The maximum number of bytes this can write in a single invocation is capped by the CHUNK size. If this is not desirable, please consider using the write_all implementation.

source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Encrypts and writes the entire buffer.

§Arguments
  • buf - The buffer to encrypt and write.
§Returns

Ok(()) on success, or an io::Error on failure.

source§

fn flush(&mut self) -> Result<()>

Flushes the underlying writer.

§Returns

Propagates the result of invoking flush for the underlying writer

1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<W, const CHUNK: usize> Freeze for Writer<W, CHUNK>
where W: Freeze,

§

impl<W, const CHUNK: usize> RefUnwindSafe for Writer<W, CHUNK>
where W: RefUnwindSafe,

§

impl<W, const CHUNK: usize> Send for Writer<W, CHUNK>
where W: Send,

§

impl<W, const CHUNK: usize> Sync for Writer<W, CHUNK>
where W: Sync,

§

impl<W, const CHUNK: usize> Unpin for Writer<W, CHUNK>
where W: Unpin,

§

impl<W, const CHUNK: usize> UnwindSafe for Writer<W, CHUNK>
where W: UnwindSafe,

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.