| 160 | #[cfg(feature = "alloc")] |
| 161 | #[test] |
| 162 | fn zeroize_string_entire_capacity() { |
| 163 | let mut string = String::from("Hello, world!"); |
| 164 | string.truncate(5); |
| 165 | |
| 166 | string.zeroize(); |
| 167 | |
| 168 | // convert the string to a vec to easily access the unused capacity |
| 169 | let mut as_vec = string.into_bytes(); |
| 170 | unsafe { as_vec.set_len(as_vec.capacity()) }; |
| 171 | |
| 172 | assert!(as_vec.iter().all(|byte| *byte == 0)); |
| 173 | } |
| 174 | |
| 175 | // TODO(tarcieri): debug flaky test (with potential UB?) See: RustCrypto/utils#774 |
| 176 | #[cfg(feature = "std")] |