Skip to content

Commit

Permalink
Partially merge #112
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Aug 2, 2022
1 parent 438ca40 commit e219866
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/impl_zeroize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use {ArrayLength, GenericArray};

use zeroize::Zeroize;

#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
impl<T: Zeroize, N: ArrayLength<T>> Zeroize for GenericArray<T, N> {
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::<u8, typenum::U2>::default();
array[0] = 4;
array[1] = 9;
array.zeroize();
assert_eq!(array[0], 0);
assert_eq!(array[1], 0);
}
}
11 changes: 3 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -577,14 +580,6 @@ impl<'a, T, N: ArrayLength<T>> From<&'a mut [T]> for &'a mut GenericArray<T, N>
}
}

#[cfg(feature = "zeroize")]
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
impl<T: zeroize::Zeroize, N: ArrayLength<T>> zeroize::Zeroize for GenericArray<T, N> {
fn zeroize(&mut self) {
self.as_mut_slice().iter_mut().zeroize()
}
}

impl<T: Clone, N> GenericArray<T, N>
where
N: ArrayLength<T>,
Expand Down

0 comments on commit e219866

Please sign in to comment.