diff --git a/Cargo.toml b/Cargo.toml index cd4c2aa..a322787 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ rand_core = "0.4.0" unicode-normalization = { version = "=0.1.9", optional = true } rand = { version = "0.6.0", optional = true } serde = { version = "1.0", default-features = false, optional = true } +zeroize = {version = "1.5", features = ["zeroize_derive"], optional = true} [dev-dependencies] rand = { version = "0.6.0", optional = false } diff --git a/src/language/mod.rs b/src/language/mod.rs index e85f95c..1f5f922 100644 --- a/src/language/mod.rs +++ b/src/language/mod.rs @@ -55,6 +55,12 @@ pub enum Language { Spanish, } +impl Default for Language { + fn default() -> Self { + Language::English + } +} + impl Language { /// The list of supported languages. /// Language support is managed by compile features. diff --git a/src/lib.rs b/src/lib.rs index 94b8795..9337e29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,11 @@ use bitcoin_hashes::{sha256, Hash}; #[cfg(feature = "std")] use unicode_normalization::UnicodeNormalization; +#[cfg(feature = "zeroize")] +extern crate zeroize; +#[cfg(feature = "zeroize")] +use zeroize::{Zeroize, ZeroizeOnDrop}; + #[macro_use] mod internal_macros; mod language; @@ -150,6 +155,7 @@ impl error::Error for Error {} /// /// Supported number of words are 12, 18 and 24. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))] pub struct Mnemonic { /// The language the mnemonic. lang: Language, @@ -158,6 +164,9 @@ pub struct Mnemonic { words: [u16; MAX_NB_WORDS], } +#[cfg(feature = "zeroize")] +impl zeroize::DefaultIsZeroes for Language {} + serde_string_impl!(Mnemonic, "a BIP-39 Mnemonic Code"); impl Mnemonic {