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

Function zeroize_vec_entire_capacity

zeroize/tests/zeroize.rs:131–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129#[cfg(feature = "alloc")]
130#[test]
131fn zeroize_vec_entire_capacity() {
132 #[derive(Clone)]
133 struct PanicOnNonZeroDrop(u64);
134
135 impl Zeroize for PanicOnNonZeroDrop {
136 fn zeroize(&mut self) {
137 self.0 = 0;
138 }
139 }
140
141 impl Drop for PanicOnNonZeroDrop {
142 fn drop(&mut self) {
143 assert!(self.0 == 0, "dropped non-zeroized data");
144 }
145 }
146
147 // Ensure that the entire capacity of the vec is zeroized and that no unitinialized data
148 // is ever interpreted as initialized
149 let mut vec = vec![PanicOnNonZeroDrop(42); 2];
150
151 unsafe {
152 vec.set_len(1);
153 }
154
155 vec.zeroize();
156
157 unsafe {
158 vec.set_len(2);
159 }
160
161 drop(vec);
162}
163
164#[cfg(feature = "alloc")]
165#[test]

Callers

nothing calls this directly

Calls 1

zeroizeMethod · 0.45

Tested by

no test coverage detected