Skip to content

Commit

Permalink
Fix ambiguous method for AssertZeroizeOnDrop (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Jan 31, 2022
1 parent a37fa8d commit ba4e7e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub mod __internal {
fn zeroize_or_on_drop(self);
}

impl<T: ZeroizeOnDrop> AssertZeroizeOnDrop for &mut T {
impl<T: ZeroizeOnDrop> AssertZeroizeOnDrop for &&mut T {
fn zeroize_or_on_drop(self) {}
}

Expand Down
32 changes: 31 additions & 1 deletion zeroize/tests/zeroize_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ mod custom_derive_tests {
}

#[test]
fn derive_only_zeroize_on_drop() {
fn derive_inherit_zeroize_on_drop() {
#[derive(ZeroizeOnDrop)]
struct X([u8; 3]);

Expand All @@ -255,4 +255,34 @@ mod custom_derive_tests {
}
assert_eq!(&value.0 .0, &[0, 0, 0])
}

#[test]
fn derive_inherit_from_both() {
#[derive(Zeroize, ZeroizeOnDrop)]
struct X([u8; 3]);

#[derive(ZeroizeOnDrop)]
struct Z(X);

let mut value = Z(X([1, 2, 3]));
unsafe {
std::ptr::drop_in_place(&mut value);
}
assert_eq!(&value.0 .0, &[0, 0, 0])
}

#[test]
fn derive_inherit_both() {
#[derive(Zeroize, ZeroizeOnDrop)]
struct X([u8; 3]);

#[derive(Zeroize, ZeroizeOnDrop)]
struct Z(X);

let mut value = Z(X([1, 2, 3]));
unsafe {
std::ptr::drop_in_place(&mut value);
}
assert_eq!(&value.0 .0, &[0, 0, 0])
}
}

0 comments on commit ba4e7e7

Please sign in to comment.