| 172 | #[cfg(feature = "alloc")] |
| 173 | #[test] |
| 174 | fn zeroize_string_entire_capacity() { |
| 175 | let mut string = String::from("Hello, world!"); |
| 176 | string.truncate(5); |
| 177 | |
| 178 | string.zeroize(); |
| 179 | |
| 180 | // convert the string to a vec to easily access the unused capacity |
| 181 | let mut as_vec = string.into_bytes(); |
| 182 | unsafe { as_vec.set_len(as_vec.capacity()) }; |
| 183 | |
| 184 | assert!(as_vec.iter().all(|byte| *byte == 0)); |
| 185 | } |
| 186 | |
| 187 | // TODO(tarcieri): debug flaky test (with potential UB?) See: RustCrypto/utils#774 |
| 188 | #[cfg(feature = "std")] |