Skip to content

extract Cipher trait - #696

Merged
vgough merged 9 commits into
masterfrom
cipher-trait-extraction
Jun 20, 2026
Merged

vgough merged 9 commits into
masterfrom
cipher-trait-extraction

Conversation

@vgough

@vgough vgough commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Adds known-vector tests for kdf and basic cipher operations.
Work on encapsulating cipher operations via a Cipher trait.

vgough added 8 commits June 20, 2026 09:52
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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::Cipher trait and migrate core layers (FUSE FS, block/file codecs, tools, tests) to use Box<dyn Cipher> / &dyn Cipher.
  • Refactor SslCipher’s internal algorithm dispatch via a boxed BlockPrimitive and add extensive golden-vector tests for cipher primitives.
  • Add config-level known-vector tests for get_cipher across config/KDF combinations; bump crate version and add a task dev-deps helper.

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.

Comment thread src/crypto/cipher.rs Resolved
Comment thread src/config.rs Resolved
@vgough
vgough merged commit f274273 into master Jun 20, 2026
1 check passed
@vgough
vgough deleted the cipher-trait-extraction branch June 20, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants