diff --git a/src/impl_zeroize.rs b/src/impl_zeroize.rs new file mode 100644 index 000000000..ef4ac0fa1 --- /dev/null +++ b/src/impl_zeroize.rs @@ -0,0 +1,25 @@ +use {ArrayLength, GenericArray}; + +use zeroize::Zeroize; + +#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] +impl> Zeroize for GenericArray { + fn zeroize(&mut self) { + self.as_mut_slice().iter_mut().zeroize() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_zeroize() { + let mut array = GenericArray::::default(); + array[0] = 4; + array[1] = 9; + array.zeroize(); + assert_eq!(array[0], 0); + assert_eq!(array[1], 0); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1a56b6eb0..414cd0215 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,9 @@ mod impls; #[cfg(feature = "serde")] mod impl_serde; +#[cfg(feature = "zeroize")] +mod impl_zeroize; + use core::iter::FromIterator; use core::marker::PhantomData; use core::mem::{MaybeUninit, ManuallyDrop}; @@ -577,14 +580,6 @@ impl<'a, T, N: ArrayLength> From<&'a mut [T]> for &'a mut GenericArray } } -#[cfg(feature = "zeroize")] -#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] -impl> zeroize::Zeroize for GenericArray { - fn zeroize(&mut self) { - self.as_mut_slice().iter_mut().zeroize() - } -} - impl GenericArray where N: ArrayLength,