Struct secured_cipher::Cipher

source ·
pub struct Cipher { /* private fields */ }
Expand description

The Cipher struct provides a common interface for cryptographic operations, specifically focusing on encryption and decryption.

Implementations§

source§

impl Cipher

source

pub fn new(mode: CipherMode) -> Self

Constructs a new Cipher instance using the specified cipher mode.

Arguments
  • mode - The mode of cipher (ChaCha20 or XChaCha20) to use.
Returns

A new instance of Cipher.

source

pub fn init(&mut self, key: &[u8], iv: &[u8]) -> &mut Self

Initializes the cipher with a key and IV (initialization vector). Sets up the cipher’s internal state for encryption or decryption.

Arguments
  • key - A byte slice representing the key.
  • iv - A byte slice representing the initialization vector.
Returns

A mutable reference to the cipher instance.

source

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

Encrypts the provided data.

Arguments
  • data - A slice of data to be encrypted.
Returns

Encrypted data as a vector of bytes (Bytes).

source

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

Decrypts the provided data.

Arguments
  • data - A slice of encrypted data to be decrypted.
Returns

Decrypted data as a vector of bytes (Bytes).

Trait Implementations§

source§

impl Default for Cipher

source§

fn default() -> Self

Provides a default instance of Cipher using the XChaCha20 mode.

Returns

A new instance of Cipher with XChaCha20 mode.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cipher

§

impl !Send for Cipher

§

impl !Sync for Cipher

§

impl Unpin for Cipher

§

impl !UnwindSafe for Cipher

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.