pub trait SegmentCipher: Send + Sync {
// Required methods
fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>;
fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
}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::SegmentCipher;
use segment_buffer::Result;
struct Rot13;
impl SegmentCipher for Rot13 {
fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>> {
Ok(plaintext.iter().map(|b| b.wrapping_add(13)).collect())
}
fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>> {
Ok(ciphertext.iter().map(|b| b.wrapping_sub(13)).collect())
}
}Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".