Skip to main content

Encryptor

Trait Encryptor 

Source
pub trait Encryptor: Send + Sync {
    // Required methods
    fn encrypt(&self, plaintext: &[u8]) -> AppResult<String>;
    fn decrypt(&self, ciphertext: &str) -> AppResult<Vec<u8>>;
    fn algorithm(&self) -> Algorithm;
}
Expand description

Trait for symmetric encryption and decryption operations.

Implementations are thread-safe and can be shared across async boundaries.

Required Methods§

Source

fn encrypt(&self, plaintext: &[u8]) -> AppResult<String>

Encrypts plaintext and returns base64-encoded ciphertext.

The ciphertext includes a random nonce prepended to the encrypted data, so each call to encrypt with the same plaintext produces different output.

Source

fn decrypt(&self, ciphertext: &str) -> AppResult<Vec<u8>>

Decrypts base64-encoded ciphertext and returns the plaintext.

Source

fn algorithm(&self) -> Algorithm

Returns the algorithm used by this encryptor.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§