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

Function zeroize_byte_ptr

zeroize/src/bulk.rs:44–60  ·  view source on GitHub ↗
(dst: *mut u8, len: usize)

Source from the content-addressed store, hash-verified

42/// typed access or drop.
43#[inline]
44pub(crate) unsafe fn zeroize_byte_ptr(dst: *mut u8, len: usize) {
45 if HAS_ASM {
46 // SAFETY: the caller supplies exclusive access to `len` writable bytes.
47 // `write_bytes` initializes every byte before constructing the slice.
48 unsafe {
49 core::ptr::write_bytes(dst, 0, len);
50 optimization_barrier(slice::from_raw_parts(dst, len));
51 }
52 } else {
53 use core::mem::MaybeUninit;
54
55 // SAFETY: the caller supplies exclusive access to this range. `MaybeUninit<u8>` permits
56 // uninitialized bytes and has byte alignment.
57 let bytes = unsafe { slice::from_raw_parts_mut(dst.cast::<MaybeUninit<u8>>(), len) };
58 volatile_fill_slice(bytes, MaybeUninit::new(0));
59 }
60}
61
62/// Fill a slice with a repeated value, preserving its type and alignment.
63#[inline(always)]

Callers 3

zeroizeMethod · 0.85
zeroize_bytesFunction · 0.85
zeroize_flat_typeFunction · 0.85

Calls 2

optimization_barrierFunction · 0.85
volatile_fill_sliceFunction · 0.85

Tested by

no test coverage detected