MCPcopy Create free account
hub / github.com/RustCrypto/utils / zeroize_c_string

Function zeroize_c_string

zeroize/tests/zeroize.rs:191–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

189#[ignore]
190#[test]
191fn zeroize_c_string() {
192 let mut cstring = CString::new("Hello, world!").expect("CString::new failed");
193 let orig_len = cstring.as_bytes().len();
194 let orig_ptr = cstring.as_bytes().as_ptr();
195 cstring.zeroize();
196 // This doesn't quite test that the original memory has been cleared, but only that
197 // cstring now owns an empty buffer
198 assert!(cstring.as_bytes().is_empty());
199 for i in 0..orig_len {
200 unsafe {
201 // Using a simple deref, only one iteration of the loop is performed
202 // presumably because after zeroize, the internal buffer has a length of one/
203 // `read_volatile` seems to "fix" this
204 // Note that this is very likely UB
205 assert_eq!(orig_ptr.add(i).read_volatile(), 0);
206 }
207 }
208}
209
210#[cfg(feature = "alloc")]
211#[test]

Callers

nothing calls this directly

Calls 3

expectMethod · 0.80
lenMethod · 0.80
zeroizeMethod · 0.45

Tested by

no test coverage detected