Skip to main content

PayloadCipher

Trait PayloadCipher 

Source
pub trait PayloadCipher: Send + Sync {
    // Required methods
    fn encrypt(&self, plaintext: &Value) -> Result<Value, CryptoError>;
    fn decrypt(&self, envelope: &Value) -> Result<Value, CryptoError>;
}
Expand description

The encrypt/decrypt boundary. A device authors an E2E op with cipher.encrypt(plaintext) as its payload; a peer holding the key recovers it with cipher.decrypt(&op.payload). Object-safe so a daemon can hold an Arc<dyn PayloadCipher> (a null/local reference now, a login-derived key later) without a type change.

Required Methods§

Source

fn encrypt(&self, plaintext: &Value) -> Result<Value, CryptoError>

Encrypt a cleartext payload into a ciphertext Envelope (as a Value).

Source

fn decrypt(&self, envelope: &Value) -> Result<Value, CryptoError>

Recover the cleartext payload from a ciphertext Envelope. Fails (CryptoError::Decrypt) on a wrong key or any tamper.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§