Encryptable

Trait Encryptable 

Source
pub trait Encryptable<const KEY_SIZE: usize> {
    // Required methods
    fn encrypt(
        &self,
        password: String,
        strategy: KeyDerivationStrategy,
    ) -> Vec<u8> ;
    fn encrypt_with_key(&self, key: &Key<KEY_SIZE, 16>) -> Vec<u8> ;
    fn encrypt_with_raw_key(&self, key: [u8; KEY_SIZE]) -> Vec<u8> ;
    fn encrypt_with_metadata<T>(
        &self,
        key: [u8; KEY_SIZE],
        metadata: T,
    ) -> Vec<u8> 
       where T: From<Vec<u8>> + Into<Vec<u8>> + Clone;
}
Expand description

The Encryptable trait provides a common interface for encryption operations. It is implemented by types that can be encrypted.

§Type Parameters

  • KEY_SIZE - The size of the key to be used for encryption.

§Methods

  • encrypt - Encrypts the type using a specified password and key derivation strategy.
  • encrypt_with_key - Encrypts the type using a specified key.
  • encrypt_with_metadata - Encrypts the type using a specified key and metadata.

Required Methods§

Source

fn encrypt(&self, password: String, strategy: KeyDerivationStrategy) -> Vec<u8>

Source

fn encrypt_with_key(&self, key: &Key<KEY_SIZE, 16>) -> Vec<u8>

Source

fn encrypt_with_raw_key(&self, key: [u8; KEY_SIZE]) -> Vec<u8>

Source

fn encrypt_with_metadata<T>(&self, key: [u8; KEY_SIZE], metadata: T) -> Vec<u8>
where T: From<Vec<u8>> + Into<Vec<u8>> + Clone,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Encryptable<KEY_SIZE> for &str

Source§

fn encrypt(&self, password: String, strategy: KeyDerivationStrategy) -> Vec<u8>

Encrypts a &str using a provided password.

§Arguments
  • password: The password to use for key derivation.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_key(&self, key: &Key<32, 16>) -> Vec<u8>

Encrypts a string using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_raw_key(&self, key: [u8; 32]) -> Vec<u8>

Encrypts a string using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_metadata<M>(&self, key: [u8; 32], metadata: M) -> Vec<u8>
where M: From<Vec<u8>> + Into<Vec<u8>> + Clone,

Encrypts an &str using a provided key and metadata.

§Arguments
  • key: The 32-byte cipher key used for encryption.
  • metadata: The metadata to be associated with the encrypted data.
§Returns

A Vec<u8> containing the encrypted data.

Source§

impl Encryptable<KEY_SIZE> for &[u8]

Source§

fn encrypt(&self, password: String, strategy: KeyDerivationStrategy) -> Vec<u8>

Encrypts a slice of bytes using a provided password.

§Arguments
  • password: The password to use for key derivation.
  • strategy: The key derivation strategy to use.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_key(&self, key: &Key<32, 16>) -> Vec<u8>

Encrypts a slice of bytes using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_raw_key(&self, key: [u8; 32]) -> Vec<u8>

Encrypts a slice of bytes using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_metadata<M>(&self, key: [u8; 32], metadata: M) -> Vec<u8>
where M: From<Vec<u8>> + Into<Vec<u8>> + Clone,

Encrypts a slice of bytes using a provided key and metadata.

§Arguments
  • key: The 32-byte cipher key used for encryption.
  • metadata: The metadata to be associated with the encrypted data.
§Returns

A Vec<u8> containing the encrypted data.

Source§

impl Encryptable<KEY_SIZE> for String

Source§

fn encrypt(&self, password: String, strategy: KeyDerivationStrategy) -> Vec<u8>

Encrypts a string using a provided password.

§Arguments
  • key: The 32-byte cipher key used for encryption.
  • strategy: The key derivation strategy to use.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_key(&self, key: &Key<32, 16>) -> Vec<u8>

Encrypts a String using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_raw_key(&self, key: [u8; 32]) -> Vec<u8>

Encrypts a String using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_metadata<M>(&self, key: [u8; 32], metadata: M) -> Vec<u8>
where M: From<Vec<u8>> + Into<Vec<u8>> + Clone,

Encrypts a String using a provided key and metadata.

§Arguments
  • key: The 32-byte cipher key used for encryption.
  • metadata: The metadata to be associated with the encrypted data.
§Returns

A Vec<u8> containing the encrypted data.

Source§

impl Encryptable<KEY_SIZE> for Vec<u8>

Source§

fn encrypt(&self, password: String, strategy: KeyDerivationStrategy) -> Vec<u8>

Encrypts a vector of bytes using a provided password.

§Arguments
  • password: The password to use for key derivation.
  • strategy: The key derivation strategy to use.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_key(&self, key: &Key<32, 16>) -> Vec<u8>

Encrypts a vector of bytes using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_raw_key(&self, key: [u8; 32]) -> Vec<u8>

Encrypts a vector of bytes using a provided key.

§Arguments
  • key: The 32-byte cipher key used for encryption.
§Returns

A Vec<u8> containing the encrypted data.

Source§

fn encrypt_with_metadata<M>(&self, key: [u8; 32], metadata: M) -> Vec<u8>
where M: From<Vec<u8>> + Into<Vec<u8>> + Clone,

Encrypts a vector of bytes using a provided key and metadata.

§Arguments
  • key: The 32-byte cipher key used for encryption.
  • metadata: The metadata to be associated with the encrypted data.
§Returns

A Vec<u8> containing the encrypted data.

Implementors§