Trait Encryptable

Source
pub trait Encryptable {
    // Required method
    fn data(&self) -> Option<&[u8]>;
}
Expand description

A trait implemented by types that can be used as input for encryption or decryption operations.

This trait provides a unified interface for different data types, allowing you to pass them directly to the encryption/decryption algorithm without requiring additional logic.

For example, you could implement this trait on a file handle to encrypt or decrypt the contents of a file directly.

§Examples

use plain_aes::{encrypt, Encryptable, CipherVersion, ModeOfOperation};
struct MyData {
    content: String,
}

impl Encryptable for MyData {
    fn data(&self) -> Option<&[u8]> {
        Some(self.content.as_bytes())
    }
}

let data = MyData { content: "example usage of Encryptable".to_string() };
let encrypted_data = encrypt(data, CipherVersion::Aes128("This lib is cool".as_bytes(), ModeOfOperation::ECB));

Required Methods§

Source

fn data(&self) -> Option<&[u8]>

Returns a dynamic slice containing the byte sequence of the content to be encrypted.

Implementations on Foreign Types§

Source§

impl Encryptable for &str

Source§

fn data(&self) -> Option<&[u8]>

Source§

impl Encryptable for &[u8]

Source§

fn data(&self) -> Option<&[u8]>

Implementors§