Repository navigation
Description
Background
Stack Encrypt is the Rust engine in packages/stack-encrypt. It is built on vitaminc, a cryptography library, whose crates vitaminc-aead and vitaminc-aead-derive are in this repository. Stack Encrypt re-exports vitaminc's Encrypt and Decrypt, each of which is both a trait and a derive macro. A Rust program derives them for a type of its own, such as struct Email(String), so that the engine can encrypt and decrypt it.
Problem
A crate that depends only on stack-encrypt cannot use the derives that stack-encrypt re-exports.
use stack_encrypt::{Decrypt, Encrypt};
#[derive(Encrypt, Decrypt)]
pub struct Email(String);
// error[E0433]: failed to resolve: could not find `vitaminc_aead` in the list of imported cratesWhy it happens:
- The derives write paths that start at the crate
::vitaminc_aead, for exampleimpl ::vitaminc_aead::Encrypt for Email. That is the default inpackages/vitaminc-aead-derive/src/attrs.rs(krate.unwrap_or_else(|| syn::parse_quote!(::vitaminc_aead))). - Rust resolves
::vitaminc_aeadonly when the crate being compiled listsvitaminc-aeadas a dependency of its own. A re-export fromstack-encryptdoes not count. #[aead(crate = "...")]can point the derive at another path, butstack-encryptdoes not re-export thevitaminc_aeadcrate, so there is no path throughstack_encryptto give it.
So every user of the derives has to add vitaminc-aead to their Cargo.toml, at a version that matches the one stack-encrypt was built with. The error does not say so. A developer who uses Stack Encrypt has no reason to know what vitaminc is.
The comment above the re-export says the opposite: callers "don't have to depend on vitaminc-aead directly for the common path" (packages/stack-encrypt/src/lib.rs, above pub use vitaminc_aead::{…}). Nothing in this repository catches the problem, because every test and example that uses the derives is in a crate that already depends on vitaminc-aead.
Verified by compiling the example above in a new crate whose only dependency is stack-encrypt, with Rust 1.94.1.
Proposal
A crate that depends only on stack-encrypt can derive Encrypt and Decrypt, with no attribute that names vitaminc.
Approaches to evaluate:
- Stack Encrypt has derives of its own.
stack-encrypt-derivegainsEncryptandDecryptmacros that produce the same code with paths throughstack_encrypt, andstack-encryptexports those in place of vitaminc's. This needs the expansion code ofvitaminc-aead-deriveto be usable as a library, and a hidden re-export ofvitaminc_aeadinstack-encryptfor the generated paths. - A hidden re-export and a documented attribute, such as
#[aead(crate = "stack_encrypt::__private::vitaminc_aead")]. This is cheaper, but the developer writes an attribute on every type, and it names vitaminc.
Also:
- A test crate that depends only on
stack-encryptand derives both traits for a newtype, a struct and an enum, built in CI, so the problem cannot return unnoticed. - Correct the comment above the re-export, and the docs that tell a user to add
vitaminc-aead.
Relationship to other work
- stack-encrypt:
keyset.encryptrefuses a derived newtype, and the error names a vitaminc trait #2012: a derived newtype works withkeyset.encryptwith no hand-written marker. Its docs say today that the user's crate needsvitaminc-aead. - feat(stack-encrypt)!: encrypt and decrypt one value known only at run time, and bound the typed decrypt to a scalar #2011: the same for
keyset.decrypt.
Activity
coderdan commentedon Nov 28, 2026
One more case for this issue, from the review of #2014.
A hand-written
Encryptimpl has the same problem as the derive. It needs three items thatstack-encryptdoes not re-export:vitaminc_aead::plaintext::Sink, for thevisitmethod;vitaminc_aead::Scalar, to make the type usable withkeyset.encrypt;vitaminc_aead::plaintext::depth, forconst DEPTH: Option<usize> = depth::SCALAR;.The
OpaqueEncodedocs describe this path, and its doctests import all three fromvitaminc_aead. So the fix here should let a crate that depends only onstack-encryptwrite anEncryptimpl by hand as well as derive one.coderdan commentedon Nov 28, 2026
I don't just think Stack Encrypt should have its own derives. I think the Stack Encrypt derives should replace the
vitaminc-aeadderives entirely.docs(stack-encrypt): say that the derive still needs vitaminc-aead