| 117 | #[cfg(feature = "alloc")] |
| 118 | #[test] |
| 119 | fn zeroize_vec_entire_capacity() { |
| 120 | #[derive(Clone)] |
| 121 | struct PanicOnNonZeroDrop(u64); |
| 122 | |
| 123 | impl Zeroize for PanicOnNonZeroDrop { |
| 124 | fn zeroize(&mut self) { |
| 125 | self.0 = 0; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | impl Drop for PanicOnNonZeroDrop { |
| 130 | fn drop(&mut self) { |
| 131 | assert!(self.0 == 0, "dropped non-zeroized data"); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // Ensure that the entire capacity of the vec is zeroized and that no unitinialized data |
| 136 | // is ever interpreted as initialized |
| 137 | let mut vec = vec![PanicOnNonZeroDrop(42); 2]; |
| 138 | |
| 139 | unsafe { |
| 140 | vec.set_len(1); |
| 141 | } |
| 142 | |
| 143 | vec.zeroize(); |
| 144 | |
| 145 | unsafe { |
| 146 | vec.set_len(2); |
| 147 | } |
| 148 | |
| 149 | drop(vec); |
| 150 | } |
| 151 | |
| 152 | #[cfg(feature = "alloc")] |
| 153 | #[test] |