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

Function zeroizing_dyn_trait

zeroize/tests/zeroize.rs:266–304  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

264// expected.
265#[test]
266fn zeroizing_dyn_trait() {
267 trait TestTrait: Zeroize {
268 fn data(&self) -> &[u8];
269 }
270
271 struct TestStruct {
272 data: [u8; 4],
273 }
274
275 impl Zeroize for TestStruct {
276 fn zeroize(&mut self) {
277 self.data.zeroize();
278 }
279 }
280
281 impl Drop for TestStruct {
282 fn drop(&mut self) {
283 self.zeroize();
284 }
285 }
286
287 impl TestTrait for TestStruct {
288 fn data(&self) -> &[u8] {
289 &self.data
290 }
291 }
292
293 let mut b: Box<Zeroizing<dyn TestTrait>> =
294 Box::new(Zeroizing::new(TestStruct { data: [1, 2, 3, 4] }));
295
296 unsafe {
297 ptr::drop_in_place(&raw mut *b);
298 }
299
300 let inner: &Zeroizing<dyn TestTrait> = &b;
301 let inner: &dyn TestTrait = core::ops::Deref::deref(inner);
302
303 assert_eq!(inner.data(), &[0, 0, 0, 0]);
304}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected