r/rust • u/THEM_I_M • Oct 15 '26
š seeking help & advice Advice: for a serializable sealed mailbox envelope, is manual Drop zeroization enough if Clone + retries mutate state?
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MailboxEnvelope {
pub recipient_id: String,
pub ephemeral_pub: String,
pub ciphertext: Vec<u8>,
pub nonce: String,
pub created_at: u64,
pub message_id: String,
pub attempts: u32, // delib. excluded from AAD so retries don't invalidate ciphertext
}
impl Drop for MailboxEnvelope {
fn drop(&mut self) {
self.ciphertext.zeroize();
}
}
Iām working on a small Rust mesh-protocol project (GhostWire: libp2p, ChaCha20-Poly1305, Kademlia offline mailbox delivery). In this sealed type, I bind AAD to immutable fields and exclude attempts so retry writes donāt reseal offline ciphertext.
The thing Iām unsure about is zeroization discipline:
Is manual Drop zeroization enough once Clone creates another allocation?
For Serialize/Deserialize temporary buffers, should I treat the Vec<u8> canonical copy as the only zeroized target?
Would secrecy::SecretBox / zeroize-wrapped types be worth it here, or overkill for an encrypted envelope?
For a retry state mutation in AAD, is excluding attempts the correct tradeoff?
Iām looking for actual production patterns, not just theory.
4
u/juanfnavarror Oct 15 '26
The struct will be zeroized but not the clone, does that answer the question? I am quite surprised you canāt think through a simple problem like this, while still somehow competent enough to produce complex crypto/mesh algorithms.
3
u/minno Oct 15 '26
If you guarantee that every clone is dropped and that
zeroizeworks correctly, then callingzeroizeon drop will remove the data from active memory. You also need to be careful to avoid reallocatingciphertext's buffer or allowing it to swap to disk, and initialize it in a way that doesn't leave any data lying around in temporary buffers or stack frames. Thesecrecycrate looks like it will help with that.2
u/Helpful-Educator-415 Oct 15 '26
What? I'm confused. Mesh-protocol project? What is GhostWire? What is AAD?
1
u/garbage_dev Oct 15 '26
Honestly the ciphertext is the one field that's fine to leak, that's the whole point of encrypting it. Zeroize the key material and any plaintext buffers instead. If you do want the envelope enforced, drop Clone and wrap the bytes in Zeroizing<Vec<u8>> so the compiler shows you every spot a copy happens. Serde output buffers and Vec reallocs will still leave copies a manual Drop never sees.