Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hkd32: remove usage of zeroize_derive #1190

Merged
merged 1 commit into from
Jul 17, 2024
Merged
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: 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
Loading