Merge pull request #13 from praveenperera/zeroize-support

Add optional zeroize support
This commit is contained in:
Steven Roose 2022-06-29 17:44:15 +01:00 committed by GitHub
commit 00d628f1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -46,6 +46,7 @@ rand_core = "0.4.0"
unicode-normalization = { version = "=0.1.9", optional = true } unicode-normalization = { version = "=0.1.9", optional = true }
rand = { version = "0.6.0", optional = true } rand = { version = "0.6.0", optional = true }
serde = { version = "1.0", default-features = false, optional = true } serde = { version = "1.0", default-features = false, optional = true }
zeroize = {version = "1.5", features = ["zeroize_derive"], optional = true}
[dev-dependencies] [dev-dependencies]
rand = { version = "0.6.0", optional = false } rand = { version = "0.6.0", optional = false }

View File

@ -55,6 +55,12 @@ pub enum Language {
Spanish, Spanish,
} }
impl Default for Language {
fn default() -> Self {
Language::English
}
}
impl Language { impl Language {
/// The list of supported languages. /// The list of supported languages.
/// Language support is managed by compile features. /// Language support is managed by compile features.

View File

@ -51,6 +51,11 @@ use bitcoin_hashes::{sha256, Hash};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use unicode_normalization::UnicodeNormalization; use unicode_normalization::UnicodeNormalization;
#[cfg(feature = "zeroize")]
extern crate zeroize;
#[cfg(feature = "zeroize")]
use zeroize::{Zeroize, ZeroizeOnDrop};
#[macro_use] #[macro_use]
mod internal_macros; mod internal_macros;
mod language; mod language;
@ -150,6 +155,7 @@ impl error::Error for Error {}
/// ///
/// Supported number of words are 12, 18 and 24. /// Supported number of words are 12, 18 and 24.
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "zeroize", derive(Zeroize, ZeroizeOnDrop))]
pub struct Mnemonic { pub struct Mnemonic {
/// The language the mnemonic. /// The language the mnemonic.
lang: Language, lang: Language,
@ -158,6 +164,9 @@ pub struct Mnemonic {
words: [u16; MAX_NB_WORDS], words: [u16; MAX_NB_WORDS],
} }
#[cfg(feature = "zeroize")]
impl zeroize::DefaultIsZeroes for Language {}
serde_string_impl!(Mnemonic, "a BIP-39 Mnemonic Code"); serde_string_impl!(Mnemonic, "a BIP-39 Mnemonic Code");
impl Mnemonic { impl Mnemonic {