File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1111/// implemented using `#[inline(never)]` and `read_volatile`.
1212///
1313/// # Examples
14- /// ```ignore
14+ /// ```
1515/// use core::num::NonZeroU32;
1616/// use zeroize::{ZeroizeOnDrop, zeroize_flat_type};
1717///
18+ /// # type ThirdPartyType = u32;
19+ ///
1820/// struct DataToZeroize {
1921/// buf: [u8; 32],
22+ /// // `ThirdPartyType` can be a type with private fields
23+ /// // defined in a third-party crate and which does not implement
24+ /// // `Zeroize` or zeroization on drop.
25+ /// data: ThirdPartyType,
2026/// pos: NonZeroU32,
2127/// }
2228///
2531/// impl Drop for DataToZeroize {
2632/// fn drop(&mut self) {
2733/// self.buf = [0u8; 32];
34+ /// self.data = ThirdPartyType::default();
2835/// self.pos = NonZeroU32::new(32).unwrap();
2936/// zeroize::optimization_barrier(self);
3037/// }
3441///
3542/// let mut data = DataToZeroize {
3643/// buf: [3u8; 32],
44+ /// data: ThirdPartyType::default(),
3745/// pos: NonZeroU32::new(32).unwrap(),
3846/// };
3947///
4048/// // data gets zeroized when dropped
4149/// ```
50+ ///
51+ /// Note that erasure of `ThirdPartyType` demonstrated above can be fragile if it contains
52+ /// `MaybeUninit` or `union` data. It also does not perform erasure of types like `Box` or `Vec`.
4253pub fn optimization_barrier < T : ?Sized > ( val : & T ) {
4354 #[ cfg( all(
4455 not( miri) ,
You can’t perform that action at this time.
0 commit comments