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

Function zeroizing_dyn_trait

zeroize/tests/zeroize.rs:278–316  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

276// expected.
277#[test]
278fn zeroizing_dyn_trait() {
279 trait TestTrait: Zeroize {
280 fn data(&self) -> &[u8];
281 }
282
283 struct TestStruct {
284 data: [u8; 4],
285 }
286
287 impl Zeroize for TestStruct {
288 fn zeroize(&mut self) {
289 self.data.zeroize();
290 }
291 }
292
293 impl Drop for TestStruct {
294 fn drop(&mut self) {
295 self.zeroize();
296 }
297 }
298
299 impl TestTrait for TestStruct {
300 fn data(&self) -> &[u8] {
301 &self.data
302 }
303 }
304
305 let mut b: Box<Zeroizing<dyn TestTrait>> =
306 Box::new(Zeroizing::new(TestStruct { data: [1, 2, 3, 4] }));
307
308 unsafe {
309 ptr::drop_in_place(&raw mut *b);
310 }
311
312 let inner: &Zeroizing<dyn TestTrait> = &b;
313 let inner: &dyn TestTrait = core::ops::Deref::deref(inner);
314
315 assert_eq!(inner.data(), &[0, 0, 0, 0]);
316}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected