Skip to content

Commit

Permalink
hkd32: remove usage of zeroize_derive
Browse files Browse the repository at this point in the history
It's being used for trivial impls of the `zeroize` traits, and in the
meantime `syn` MSRV changes are breaking the crate's current MSRV.

The derived usages are trivially rewritten without the whole proc macro
stack, and really these types shouldn't have `Zeroize` impls at all, but
instead impl `Drop` and `ZeroizeOnDrop`.
  • Loading branch information
tony-iqlusion committed Jul 17, 2024
1 parent e327dec commit ede9f28
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
14 changes: 0 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hkd32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rust-version = "1.60"
hmac = { version = "0.12", default-features = false }
rand_core = { version = "0.6", default-features = false }
sha2 = { version = "0.10", default-features = false }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }
zeroize = { version = "1", default-features = false }

# optional dependencies
once_cell = { version = "1", optional = true }
Expand Down
16 changes: 14 additions & 2 deletions hkd32/src/key_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use crate::mnemonic;
///
/// This type provides the main key derivation functionality and is used to
/// represent both input and output key material.
#[derive(Clone, Zeroize)]
#[zeroize(drop)]
#[derive(Clone)]
pub struct KeyMaterial([u8; KEY_SIZE]);

impl KeyMaterial {
Expand Down Expand Up @@ -125,6 +124,12 @@ impl KeyMaterial {
}
}

impl Drop for KeyMaterial {
fn drop(&mut self) {
self.zeroize();
}
}

impl From<[u8; KEY_SIZE]> for KeyMaterial {
fn from(bytes: [u8; KEY_SIZE]) -> Self {
Self::new(bytes)
Expand All @@ -138,3 +143,10 @@ impl<'a> TryFrom<&'a [u8]> for KeyMaterial {
Self::from_bytes(slice)
}
}

// TODO(tarcieri): remove this impl in favor of `ZeroizeOnDrop` in next breaking release
impl Zeroize for KeyMaterial {
fn zeroize(&mut self) {
self.0.zeroize();
}
}
16 changes: 14 additions & 2 deletions hkd32/src/pathbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use zeroize::Zeroize;
///
/// This is the owned path type. The corresponding reference type is
/// `hkd32::Path` (ala the corresponding types in `std`).
#[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord, Zeroize)]
#[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[repr(transparent)]
#[zeroize(drop)]
pub struct PathBuf(Vec<u8>);

impl PathBuf {
Expand Down Expand Up @@ -91,6 +90,12 @@ impl Deref for PathBuf {
}
}

impl Drop for PathBuf {
fn drop(&mut self) {
self.0.zeroize();
}
}

impl FromStr for PathBuf {
type Err = Error;

Expand Down Expand Up @@ -136,6 +141,13 @@ impl ToOwned for Path {
}
}

// TODO(tarcieri): remove this impl in favor of `ZeroizeOnDrop` in next breaking release
impl Zeroize for PathBuf {
fn zeroize(&mut self) {
self.0.zeroize();
}
}

#[cfg(all(test, feature = "alloc"))]
mod tests {
use super::*;
Expand Down

0 comments on commit ede9f28

Please sign in to comment.