Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions zeroize/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use syn::{
Attribute, Data, DeriveInput, Expr, ExprLit, Field, Fields, Lit, Meta, Result, Variant,
WherePredicate,
parse::{Parse, ParseStream},
parse_quote,
punctuated::Punctuated,
token::Comma,
visit::Visit,
Attribute, Data, DeriveInput, Expr, ExprLit, Field, Fields, Lit, Meta, Result, Variant,
WherePredicate,
};

/// Name of zeroize-related attributes
Expand Down Expand Up @@ -454,7 +454,7 @@ mod tests {
impl ::zeroize::Zeroize for Z {
fn zeroize(&mut self) {
match self {
#[allow(unused_variables)]
#[allow(unused_variables, unused_assignments)]
Z { a, b, c } => {
a.zeroize();
b.zeroize();
Expand Down Expand Up @@ -484,7 +484,7 @@ mod tests {
impl ::zeroize::Zeroize for Z {
fn zeroize(&mut self) {
match self {
#[allow(unused_variables)]
#[allow(unused_variables, unused_assignments)]
Z { a, b, c } => {
a.zeroize();
b.zeroize();
Expand Down Expand Up @@ -520,7 +520,7 @@ mod tests {
impl ::zeroize::Zeroize for Z {
fn zeroize(&mut self) {
match self {
#[allow(unused_variables)]
#[allow(unused_variables, unused_assignments)]
Z { a, b, c } => {
a.zeroize();
b.zeroize()
Expand All @@ -545,7 +545,7 @@ mod tests {
impl<T> ::zeroize::Zeroize for Z<T> where T: MyTrait {
fn zeroize(&mut self) {
match self {
#[allow(unused_variables)]
#[allow(unused_variables, unused_assignments)]
Z(__zeroize_field_0) => {
__zeroize_field_0.zeroize()
}
Expand Down Expand Up @@ -574,7 +574,7 @@ mod tests {
use ::zeroize::__internal::AssertZeroize;
use ::zeroize::__internal::AssertZeroizeOnDrop;
match self {
#[allow(unused_variables)]
#[allow(unused_variables, unused_assignments)]
Z { a, b, c } => {
a.zeroize_or_on_drop();
b.zeroize_or_on_drop();
Expand Down
8 changes: 4 additions & 4 deletions zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod x86;

use core::{
marker::{PhantomData, PhantomPinned},
mem::{self, MaybeUninit},
mem::{size_of, MaybeUninit},
num::{
self, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize,
NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
Expand All @@ -269,7 +269,7 @@ use {
};

#[cfg(feature = "std")]
use std::ffi::CString;
use {core::mem, std::ffi::CString};

/// Trait for securely erasing values from memory.
pub trait Zeroize {
Expand Down Expand Up @@ -405,7 +405,7 @@ where
// The memory pointed to by `self` is valid for `mem::size_of::<Self>()` bytes.
// It is also properly aligned, because `u8` has an alignment of `1`.
unsafe {
volatile_set(self as *mut _ as *mut u8, 0, mem::size_of::<Self>());
volatile_set(self as *mut _ as *mut u8, 0, size_of::<Self>());
}

// Ensures self is overwritten with the default bit pattern. volatile_write can't be
Expand Down Expand Up @@ -436,7 +436,7 @@ impl<Z> ZeroizeOnDrop for Option<Z> where Z: ZeroizeOnDrop {}
impl<Z> Zeroize for [MaybeUninit<Z>] {
fn zeroize(&mut self) {
let ptr = self.as_mut_ptr() as *mut MaybeUninit<u8>;
let size = self.len().checked_mul(mem::size_of::<Z>()).unwrap();
let size = self.len().checked_mul(size_of::<Z>()).unwrap();
assert!(size <= isize::MAX as usize);

// Safety:
Expand Down
4 changes: 4 additions & 0 deletions zeroize/tests/zeroize_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ fn derive_deref() {

#[test]
#[cfg(feature = "alloc")]
#[allow(dead_code)]
fn derive_zeroize_on_drop_generic() {
#[derive(ZeroizeOnDrop)]
struct Y<T: Zeroize>(Box<T>);
Expand All @@ -327,6 +328,7 @@ fn derive_zeroize_on_drop_generic() {
}

#[test]
#[allow(dead_code)]
fn derive_zeroize_unused_param() {
#[derive(Zeroize)]
struct Z<T> {
Expand All @@ -337,6 +339,7 @@ fn derive_zeroize_unused_param() {
}

#[test]
#[allow(dead_code)]
// Issue #878
fn derive_zeroize_with_marker() {
#[derive(ZeroizeOnDrop, Zeroize)]
Expand All @@ -353,6 +356,7 @@ fn derive_zeroize_with_marker() {
}

#[test]
#[allow(dead_code)]
// Issue #878
fn derive_zeroize_used_param() {
#[derive(Zeroize)]
Expand Down