Skip to main content

SegmentCipher

Trait SegmentCipher 

Source
pub trait SegmentCipher: Send + Sync {
    // Required methods
    fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, CipherError>;
    fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CipherError>;
}
Expand description

Encrypts and decrypts segment file payloads.

Implementations must be Send + Sync because the buffer is shared across threads via Arc<SegmentBuffer>.

The ciphertext format is implementation-defined but must be self-describing: decrypt must be able to recover the plaintext from the exact bytes returned by encrypt without external state.

§Example

use segment_buffer::{CipherError, SegmentCipher};

struct Rot13;

impl SegmentCipher for Rot13 {
    fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, CipherError> {
        Ok(plaintext.iter().map(|b| b.wrapping_add(13)).collect())
    }
    fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CipherError> {
        Ok(ciphertext.iter().map(|b| b.wrapping_sub(13)).collect())
    }
}

Required Methods§

Source

fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, CipherError>

Encrypt plaintext, returning self-describing ciphertext.

Source

fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CipherError>

Decrypt previously-produced ciphertext back to the original plaintext.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§