Skip to content
Open
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
16 changes: 14 additions & 2 deletions crates/bip39/src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum MnemonicError {
}

/// Holds valid entropy lengths for a mnemonic
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub enum Entropy {
/// Sixteen bytes of entropy
Sixteen([u8; 16]),
Expand Down Expand Up @@ -177,6 +177,18 @@ impl Fill for Entropy {
}
}

impl Drop for Entropy {
fn drop(&mut self) {
match self {
Entropy::Sixteen(arr) => arr.as_mut_slice().fill(0),
Entropy::Twenty(arr) => arr.as_mut_slice().fill(0),
Entropy::TwentyFour(arr) => arr.as_mut_slice().fill(0),
Entropy::TwentyEight(arr) => arr.as_mut_slice().fill(0),
Entropy::ThirtyTwo(arr) => arr.as_mut_slice().fill(0),
}
}
}

/// Mnemonic represents entropy that can be represented as a phrase. A mnemonic can be used to
/// deterministically generate an extended private key or derive its child keys.
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -560,7 +572,7 @@ mod tests {
.try_into()
.unwrap();
let mnemonic = Mnemonic::<W> {
entropy,
entropy: entropy.clone(),
_wordlist: PhantomData,
};
assert_eq!(mnemonic.entropy, entropy);
Expand Down