Skip to content

Conversation

@ssanderson
Copy link
Contributor

This commit adds ?Sized to the generic bounds on Zeroizing and many of its trait implementations. This makes it possible to form and use types like Zeroizing<Box<[u8]>> and Zeroizing<Arc<[u8]>>.

This also allows forming more exotic types like Zeroizing<dyn SomeTrait> where SomeTrait: Zeroize. I've included a test for that case to ensure that nothing unexpected breaks if it's used in that way, but that usage is probably not to be recommended.

See #1256 for more details.

@ssanderson ssanderson force-pushed the zeroizing-unsized branch 2 times, most recently from 6a5c7cc to c20be21 Compare December 30, 2025 17:43
This commit adds ?Sized to the generic bounds on Zeroizing and many of its
trait implementations. This makes it possible to form and use types like
`Zeroizing<Box<[u8]>>` and `Zeroizing<Arc<[u8]>>`.
// This is a weird way to use zeroizing, but it's technically allowed b/c
// unsized types can be stored inside Zeroizing, so make sure it works as
// expected.
#[test]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is missing a feature = "alloc" guard since it uses Box, but it seems like the build is still passing. Are these guards actually required?

Copy link
Member

Choose a reason for hiding this comment

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

Since these tests are in tests/ they're in their own toplevel crate which links alloc and std by default.

You only need to gate alloc if it's using alloc-dependent functionality inside Zeroize. Since this is Box<Zeroizing<[u8]>> and not Zeroizing<Box<[u8]>> (which would need the Zeroize impl on Box) you're not actually dependent on zeroize having its alloc feature enabled.

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