From 14d4504daef188a156e9381d18e2b87f6a6224e5 Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Tue, 14 Nov 2023 04:19:20 +0100 Subject: [PATCH 1/3] rustfmt: skip language files --- src/language/chinese_simplified.rs | 1 + src/language/chinese_traditional.rs | 1 + src/language/czech.rs | 1 + src/language/english.rs | 1 + src/language/french.rs | 1 + src/language/italian.rs | 1 + src/language/japanese.rs | 1 + src/language/korean.rs | 1 + src/language/portuguese.rs | 1 + src/language/spanish.rs | 1 + 10 files changed, 10 insertions(+) diff --git a/src/language/chinese_simplified.rs b/src/language/chinese_simplified.rs index 6498fda..87e9290 100644 --- a/src/language/chinese_simplified.rs +++ b/src/language/chinese_simplified.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "的", "一", diff --git a/src/language/chinese_traditional.rs b/src/language/chinese_traditional.rs index 711fe6a..d496500 100644 --- a/src/language/chinese_traditional.rs +++ b/src/language/chinese_traditional.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "的", "一", diff --git a/src/language/czech.rs b/src/language/czech.rs index 8768963..5d6b6d4 100644 --- a/src/language/czech.rs +++ b/src/language/czech.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "abdikace", "abeceda", diff --git a/src/language/english.rs b/src/language/english.rs index 0d244aa..737e6af 100644 --- a/src/language/english.rs +++ b/src/language/english.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "abandon", "ability", diff --git a/src/language/french.rs b/src/language/french.rs index 2796cdc..ed40b64 100644 --- a/src/language/french.rs +++ b/src/language/french.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "abaisser", "abandon", diff --git a/src/language/italian.rs b/src/language/italian.rs index d730fd7..98563d1 100644 --- a/src/language/italian.rs +++ b/src/language/italian.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "abaco", "abbaglio", diff --git a/src/language/japanese.rs b/src/language/japanese.rs index 8930380..8fe59a8 100644 --- a/src/language/japanese.rs +++ b/src/language/japanese.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "あいこくしん", "あいさつ", diff --git a/src/language/korean.rs b/src/language/korean.rs index f8eb810..37edacb 100644 --- a/src/language/korean.rs +++ b/src/language/korean.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "가격", "가끔", diff --git a/src/language/portuguese.rs b/src/language/portuguese.rs index 072a883..e564646 100644 --- a/src/language/portuguese.rs +++ b/src/language/portuguese.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "abacate", "abaixo", diff --git a/src/language/spanish.rs b/src/language/spanish.rs index d6c6553..4e0d996 100644 --- a/src/language/spanish.rs +++ b/src/language/spanish.rs @@ -1,3 +1,4 @@ +#[rustfmt::skip] pub const WORDS: [&str; 2048] = [ "ábaco", "abdomen", From 35e74e60babf016a6d729f99fd1dbb37b89f1068 Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Tue, 14 Nov 2023 04:19:43 +0100 Subject: [PATCH 2/3] run rustfmt Not a lot of changes, and it is good to keep consistent with rustfmt as many editors and rust-analyzer automatically apply it. --- src/internal_macros.rs | 2 +- src/lib.rs | 11 +++-------- src/pbkdf2.rs | 12 ++++++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 4d4ece1..6fef027 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -8,9 +8,9 @@ macro_rules! serde_string_impl { where D: $crate::serde::de::Deserializer<'de>, { + use alloc::string::String; use core::fmt::{self, Formatter}; use core::str::FromStr; - use alloc::string::String; struct Visitor; impl<'de> $crate::serde::de::Visitor<'de> for Visitor { diff --git a/src/lib.rs b/src/lib.rs index 4f7b915..42c02ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,10 +36,10 @@ extern crate bitcoin_hashes; #[cfg(feature = "std")] extern crate unicode_normalization; -#[cfg(feature = "rand_core")] -pub extern crate rand_core; #[cfg(feature = "rand")] pub extern crate crate_rand as rand; +#[cfg(feature = "rand_core")] +pub extern crate rand_core; #[cfg(feature = "serde")] pub extern crate serde; @@ -542,12 +542,7 @@ impl Mnemonic { const PBKDF2_BYTES: usize = 64; let mut seed = [0u8; PBKDF2_BYTES]; - pbkdf2::pbkdf2( - self.words(), - normalized_passphrase.as_bytes(), - PBKDF2_ROUNDS, - &mut seed, - ); + pbkdf2::pbkdf2(self.words(), normalized_passphrase.as_bytes(), PBKDF2_ROUNDS, &mut seed); seed } diff --git a/src/pbkdf2.rs b/src/pbkdf2.rs index e7d3375..b45125e 100644 --- a/src/pbkdf2.rs +++ b/src/pbkdf2.rs @@ -4,7 +4,8 @@ const SALT_PREFIX: &'static str = "mnemonic"; /// Calculate the binary size of the mnemonic. fn mnemonic_byte_len(mnemonic: M) -> usize - where M: Iterator + Clone, +where + M: Iterator + Clone, { let mut len = 0; for (i, word) in mnemonic.enumerate() { @@ -18,7 +19,8 @@ fn mnemonic_byte_len(mnemonic: M) -> usize /// Wrote the mnemonic in binary form into the hash engine. fn mnemonic_write_into(mnemonic: M, engine: &mut sha512::HashEngine) - where M: Iterator + Clone, +where + M: Iterator + Clone, { for (i, word) in mnemonic.enumerate() { if i > 0 { @@ -32,7 +34,8 @@ fn mnemonic_write_into(mnemonic: M, engine: &mut sha512::HashEngine) /// We need a special method because we can't allocate a new byte /// vector for the entire serialized mnemonic. fn create_hmac_engine(mnemonic: M) -> hmac::HmacEngine - where M: Iterator + Clone, +where + M: Iterator + Clone, { // Inner code is borrowed from the bitcoin_hashes::hmac::HmacEngine::new method. let mut ipad = [0x36u8; 128]; @@ -97,7 +100,8 @@ fn xor(res: &mut [u8], salt: &[u8]) { /// PBKDF2-HMAC-SHA512 implementation using bitcoin_hashes. pub(crate) fn pbkdf2(mnemonic: M, unprefixed_salt: &[u8], c: usize, res: &mut [u8]) - where M: Iterator + Clone, +where + M: Iterator + Clone, { let prf = create_hmac_engine(mnemonic); From 28f5b7cfd4d5a24a9cce3142a49f9fd890836e42 Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Tue, 14 Nov 2023 04:22:52 +0100 Subject: [PATCH 3/3] fix some important std unit tests that were not running due to typo `#[cfg(features = "std")]` is invalid and always disabled the whole block. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 42c02ab..d864f1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -842,7 +842,7 @@ mod tests { mnemonic_str ); - #[cfg(features = "std")] + #[cfg(feature = "std")] { assert_eq!(&mnemonic.to_string(), mnemonic_str, "failed vector: {}", mnemonic_str); assert_eq!(