Skip to content

Commit

Permalink
fix: prevent accidental debug logging of entropy
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Mar 7, 2023
1 parent 159a7a0 commit 1ead714
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bip39/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coins-bip39"
version = "0.8.0"
version = "0.8.1"
authors = ["Rohit Narurkar <[email protected]>"]
edition = "2018"
description = "Bip39 in Rust"
Expand Down
14 changes: 13 additions & 1 deletion 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(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum Entropy {
/// Sixteen bytes of entropy
Sixteen([u8; 16]),
Expand All @@ -46,6 +46,18 @@ pub enum Entropy {
ThirtyTwo([u8; 32]),
}

impl std::fmt::Debug for Entropy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Sixteen(_) => f.debug_tuple("Sixteen bytes").finish(),
Self::Twenty(_) => f.debug_tuple("Twenty bytes").finish(),
Self::TwentyFour(_) => f.debug_tuple("Twenty-four bytes").finish(),
Self::TwentyEight(_) => f.debug_tuple("Twenty-eight bytes").finish(),
Self::ThirtyTwo(_) => f.debug_tuple("Thirty-two bytes").finish(),
}
}
}

impl std::convert::TryFrom<&[u8]> for Entropy {
type Error = MnemonicError;

Expand Down

0 comments on commit 1ead714

Please sign in to comment.