| 129 | #[cfg(feature = "alloc")] |
| 130 | #[test] |
| 131 | fn zeroize_vec_entire_capacity() { |
| 132 | #[derive(Clone)] |
| 133 | struct PanicOnNonZeroDrop(u64); |
| 134 | |
| 135 | impl Zeroize for PanicOnNonZeroDrop { |
| 136 | fn zeroize(&mut self) { |
| 137 | self.0 = 0; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | impl Drop for PanicOnNonZeroDrop { |
| 142 | fn drop(&mut self) { |
| 143 | assert!(self.0 == 0, "dropped non-zeroized data"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Ensure that the entire capacity of the vec is zeroized and that no unitinialized data |
| 148 | // is ever interpreted as initialized |
| 149 | let mut vec = vec![PanicOnNonZeroDrop(42); 2]; |
| 150 | |
| 151 | unsafe { |
| 152 | vec.set_len(1); |
| 153 | } |
| 154 | |
| 155 | vec.zeroize(); |
| 156 | |
| 157 | unsafe { |
| 158 | vec.set_len(2); |
| 159 | } |
| 160 | |
| 161 | drop(vec); |
| 162 | } |
| 163 | |
| 164 | #[cfg(feature = "alloc")] |
| 165 | #[test] |