Repository navigation
extract Cipher trait - #696
Merged
Merged
Conversation
Construction and key derivation stay off the trait (no &self receiver) to preserve object safety. SslCipher implements Cipher by forwarding to its existing inherent methods — inherent methods win method resolution on a concrete receiver, so the forwarding does not recurse.
SslCipher now holds a `Box<dyn BlockPrimitive>` selected once in `new()`; the CBC/CFB bodies are written once and shared by AES-128/192/256 and Blowfish via the cipher type parameter. Adding a cipher becomes a new `Primitive::<New>` arm in the factory rather than four new match arms. block_size() now derives from iv_len (equal for all supported ciphers).
- config::get_cipher now returns Box<dyn Cipher>. - BlockCodec, FileEncoder, and FileDecoder borrow &dyn Cipher. - EncFs and ReverseFs own Box<dyn Cipher> - Cipher gains a Send + Sync supertrait so the FUSE filesystems stay thread-safe for fuse_mt; SslCipher already satisfies it. - encfsctl's path/export helpers take &dyn Cipher - Tests that build a concrete cipher wrap it with Box::new at EncFs::new
There was a problem hiding this comment.
Pull request overview
This PR introduces an object-safe Cipher trait to decouple filesystem/codecs from the concrete SslCipher implementation, while adding “golden vector” regression tests to lock down key derivation and cipher behavior to prevent on-disk format drift during the refactor.
Changes:
- Add
crypto::cipher::Ciphertrait and migrate core layers (FUSE FS, block/file codecs, tools, tests) to useBox<dyn Cipher>/&dyn Cipher. - Refactor
SslCipher’s internal algorithm dispatch via a boxedBlockPrimitiveand add extensive golden-vector tests for cipher primitives. - Add config-level known-vector tests for
get_cipheracross config/KDF combinations; bump crate version and add atask dev-depshelper.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/xattr_test.rs | Updates test filesystem setup to pass a boxed cipher into EncFs. |
| tests/write_test.rs | Adapts write tests to the boxed Cipher interface on EncFs::new. |
| tests/write_compat_test.rs | Updates compatibility write tests to construct EncFs with Box<dyn Cipher>. |
| tests/truncate_corrupt_test.rs | Migrates truncate/corruption tests to use boxed cipher construction. |
| tests/symlink_type_test.rs | Updates symlink tests for EncFs::new(..., Box::new(cipher), ...). |
| tests/rename_symlink_in_dir_test.rs | Boxes cipher in test setup to match new EncFs API. |
| tests/permissions_test.rs | Boxes cipher in permissions test setup. |
| tests/open_trunc_test.rs | Boxes cipher when building EncFs in open+truncate tests. |
| tests/mknod_test.rs | Boxes cipher in mknod test setup. |
| tests/legacy.rs | Switches decoder construction to use encfs.cipher.as_ref() (trait object). |
| tests/config_compatibility.rs | Updates decoders to accept &dyn Cipher via encfs.cipher.as_ref(). |
| Taskfile.yml | Adds dev-deps task to install cargo-nextest. |
| src/reverse_fs.rs | Stores cipher as Box<dyn Cipher> and passes &dyn Cipher into codecs. |
| src/lib.rs | Updates internal tests to pass cipher.as_ref() into file decoder helpers. |
| src/fs.rs | Changes EncFs to own Box<dyn Cipher> and updates call sites to use as_ref(). |
| src/encfsctl.rs | Generalizes helpers to accept &dyn Cipher and returns boxed ciphers from config. |
| src/crypto/ssl.rs | Replaces per-algorithm match dispatch with BlockPrimitive + adds golden vectors. |
| src/crypto/mod.rs | Exports the new crypto::cipher module. |
| src/crypto/file.rs | Generalizes file encoder/decoder to accept &dyn Cipher. |
| src/crypto/cipher.rs | Adds the Cipher trait, a build factory, and the SslCipher trait impl. |
| src/crypto/block.rs | Generalizes BlockCodec to accept &dyn Cipher. |
| src/config.rs | Makes get_cipher return Box<dyn Cipher> and adds golden tests for version/KDF dispatch. |
| fuzz/fuzz_targets/fuzz_file_ops.rs | Updates fuzz harness to construct EncFs with a boxed cipher. |
| Cargo.toml | Bumps crate version to 2.0.0-beta.2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds known-vector tests for kdf and basic cipher operations.
Work on encapsulating cipher operations via a Cipher trait.