Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const LANG: Language = Language::Spanish;
#[bench]
fn validate(b: &mut Bencher) {
let entropy = "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f".as_bytes();
let mnemonic = Mnemonic::from_entropy_in(LANG, &entropy).unwrap();
let mnemonic = Mnemonic::from_entropy_in(LANG, entropy).unwrap();
assert_eq!(mnemonic.word_count(), 24);
let phrase = mnemonic.to_string();

Expand All @@ -52,7 +52,7 @@ fn from_entropy(b: &mut Bencher) {
let entropy = "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f".as_bytes();

b.iter(|| {
let _ = Mnemonic::from_entropy_in(LANG, &entropy).unwrap();
let _ = Mnemonic::from_entropy_in(LANG, entropy).unwrap();
});
}

Expand All @@ -66,7 +66,7 @@ fn new_mnemonic(b: &mut Bencher) {
#[bench]
fn to_seed(b: &mut Bencher) {
let entropy = "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f".as_bytes();
let m = Mnemonic::from_entropy_in(LANG, &entropy).unwrap();
let m = Mnemonic::from_entropy_in(LANG, entropy).unwrap();

b.iter(|| {
let _ = m.to_seed("");
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.41.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interested what this does exactly.

2 changes: 1 addition & 1 deletion src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ macro_rules! serde_string_impl {
}

#[cfg(feature = "serde")]
impl<'de> $crate::serde::Serialize for $name {
impl $crate::serde::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: $crate::serde::Serializer,
Expand Down
2 changes: 1 addition & 1 deletion src/language/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod tests {
let mut digest = sha256::Hash::engine();
for (_idx, word) in lang.word_list().iter().enumerate() {
#[cfg(feature = "std")]
assert!(::unicode_normalization::is_nfkd(&word));
assert!(::unicode_normalization::is_nfkd(word));
digest.input(word.as_bytes());
digest.input("\n".as_bytes());
}
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//! # BIP39 Mnemonic Codes
//!
//! https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
//! <https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki>
//!

#![deny(non_upper_case_globals)]
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Mnemonic {
/// can be avoided for languages without special UTF8 characters.
#[inline]
#[cfg(feature = "std")]
pub fn normalize_utf8_cow<'a>(cow: &mut Cow<'a, str>) {
pub fn normalize_utf8_cow(cow: &mut Cow<'_, str>) {
let is_nfkd = unicode_normalization::is_nfkd_quick(cow.as_ref().chars());
if is_nfkd != unicode_normalization::IsNormalized::Yes {
*cow = Cow::Owned(cow.as_ref().nfkd().to_string());
Expand All @@ -207,7 +207,7 @@ impl Mnemonic {
return Err(Error::BadEntropyBitCount(nb_bits));
}

let check = sha256::Hash::hash(&entropy);
let check = sha256::Hash::hash(entropy);
let mut bits = [false; MAX_ENTROPY_BITS + MAX_CHECKSUM_BITS];
for i in 0..nb_bytes {
for j in 0..8 {
Expand Down Expand Up @@ -328,7 +328,7 @@ impl Mnemonic {
{
// Start scope to drop first_word so that words can be reborrowed later.
let first_word = words.peek().ok_or(Error::BadWordCount(0))?;
if first_word.len() == 0 {
if first_word.is_empty() {
return Err(Error::BadWordCount(0));
}

Expand Down Expand Up @@ -372,7 +372,7 @@ impl Mnemonic {
}
}

return Err(Error::AmbiguousLanguages(AmbiguousLanguages(possible)));
Err(Error::AmbiguousLanguages(AmbiguousLanguages(possible)))
}

/// Determine the language of the mnemonic.
Expand Down Expand Up @@ -789,9 +789,9 @@ mod tests {
];

for vector in &test_vectors {
let entropy = Vec::<u8>::from_hex(&vector.0).unwrap();
let entropy = Vec::<u8>::from_hex(vector.0).unwrap();
let mnemonic_str = vector.1;
let seed = Vec::<u8>::from_hex(&vector.2).unwrap();
let seed = Vec::<u8>::from_hex(vector.2).unwrap();

let mnemonic = Mnemonic::from_entropy(&entropy).unwrap();

Expand Down Expand Up @@ -883,13 +883,13 @@ mod tests {
#[test]
fn test_invalid_entropy() {
//between 128 and 256 bits, but not divisible by 32
assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 17]), Err(Error::BadEntropyBitCount(136)));
assert_eq!(Mnemonic::from_entropy(&[b'x'; 17]), Err(Error::BadEntropyBitCount(136)));

//less than 128 bits
assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 4]), Err(Error::BadEntropyBitCount(32)));
assert_eq!(Mnemonic::from_entropy(&[b'x'; 4]), Err(Error::BadEntropyBitCount(32)));

//greater than 256 bits
assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 36]), Err(Error::BadEntropyBitCount(288)));
assert_eq!(Mnemonic::from_entropy(&[b'x'; 36]), Err(Error::BadEntropyBitCount(288)));
}

#[cfg(all(feature = "japanese", feature = "std"))]
Expand Down Expand Up @@ -1050,10 +1050,10 @@ mod tests {
];

for vector in &vectors {
let entropy = Vec::<u8>::from_hex(&vector.0).unwrap();
let entropy = Vec::<u8>::from_hex(vector.0).unwrap();
let mnemonic_str = vector.1;
let passphrase = vector.2;
let seed = Vec::<u8>::from_hex(&vector.3).unwrap();
let seed = Vec::<u8>::from_hex(vector.3).unwrap();

let mnemonic = Mnemonic::from_entropy_in(Language::Japanese, &entropy).unwrap();

Expand Down
8 changes: 4 additions & 4 deletions src/pbkdf2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitcoin_hashes::{hmac, sha512, Hash, HashEngine};

const SALT_PREFIX: &'static str = "mnemonic";
const SALT_PREFIX: &str = "mnemonic";

/// Calculate the binary size of the mnemonic.
fn mnemonic_byte_len<M>(mnemonic: M) -> usize
Expand Down Expand Up @@ -58,8 +58,8 @@ fn create_hmac_engine<M>(mnemonic: M) -> hmac::HmacEngine<sha512::Hash>
let mut cursor = 0;
for (i, word) in mnemonic.enumerate() {
if i > 0 {
ipad[cursor] ^= ' ' as u8;
opad[cursor] ^= ' ' as u8;
ipad[cursor] ^= b' ';
opad[cursor] ^= b' ';
cursor += 1;
}
for (b_i, b_h) in ipad.iter_mut().skip(cursor).zip(word.as_bytes()) {
Expand All @@ -83,7 +83,7 @@ fn create_hmac_engine<M>(mnemonic: M) -> hmac::HmacEngine<sha512::Hash>
fn u32_to_array_be(val: u32) -> [u8; 4] {
let mut res = [0; 4];
for i in 0..4 {
res[i] = ((val >> (4 - i - 1) * 8) & 0xff) as u8;
res[i] = ((val >> ((4 - i - 1) * 8)) & 0xff) as u8;
}
res
}
Expand Down