Skip to content

Commit 4ec9088

Browse files
hkd32: remove usage of zeroize_derive (#1190)
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`.
1 parent f21787a commit 4ec9088

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hkd32/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rust-version = "1.60"
2222
hmac = { version = "0.12", default-features = false }
2323
rand_core = { version = "0.6", default-features = false }
2424
sha2 = { version = "0.10", default-features = false }
25-
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }
25+
zeroize = { version = "1", default-features = false }
2626

2727
# optional dependencies
2828
once_cell = { version = "1", optional = true }

hkd32/src/key_material.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use crate::mnemonic;
2323
///
2424
/// This type provides the main key derivation functionality and is used to
2525
/// represent both input and output key material.
26-
#[derive(Clone, Zeroize)]
27-
#[zeroize(drop)]
26+
#[derive(Clone)]
2827
pub struct KeyMaterial([u8; KEY_SIZE]);
2928

3029
impl KeyMaterial {
@@ -125,6 +124,12 @@ impl KeyMaterial {
125124
}
126125
}
127126

127+
impl Drop for KeyMaterial {
128+
fn drop(&mut self) {
129+
self.zeroize();
130+
}
131+
}
132+
128133
impl From<[u8; KEY_SIZE]> for KeyMaterial {
129134
fn from(bytes: [u8; KEY_SIZE]) -> Self {
130135
Self::new(bytes)
@@ -138,3 +143,10 @@ impl<'a> TryFrom<&'a [u8]> for KeyMaterial {
138143
Self::from_bytes(slice)
139144
}
140145
}
146+
147+
// TODO(tarcieri): remove this impl in favor of `ZeroizeOnDrop` in next breaking release
148+
impl Zeroize for KeyMaterial {
149+
fn zeroize(&mut self) {
150+
self.0.zeroize();
151+
}
152+
}

hkd32/src/pathbuf.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use zeroize::Zeroize;
1717
///
1818
/// This is the owned path type. The corresponding reference type is
1919
/// `hkd32::Path` (ala the corresponding types in `std`).
20-
#[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord, Zeroize)]
20+
#[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
2121
#[repr(transparent)]
22-
#[zeroize(drop)]
2322
pub struct PathBuf(Vec<u8>);
2423

2524
impl PathBuf {
@@ -91,6 +90,12 @@ impl Deref for PathBuf {
9190
}
9291
}
9392

93+
impl Drop for PathBuf {
94+
fn drop(&mut self) {
95+
self.0.zeroize();
96+
}
97+
}
98+
9499
impl FromStr for PathBuf {
95100
type Err = Error;
96101

@@ -136,6 +141,13 @@ impl ToOwned for Path {
136141
}
137142
}
138143

144+
// TODO(tarcieri): remove this impl in favor of `ZeroizeOnDrop` in next breaking release
145+
impl Zeroize for PathBuf {
146+
fn zeroize(&mut self) {
147+
self.0.zeroize();
148+
}
149+
}
150+
139151
#[cfg(all(test, feature = "alloc"))]
140152
mod tests {
141153
use super::*;

0 commit comments

Comments
 (0)