diff --git a/benches/bench.rs b/benches/bench.rs index 9d1c316..1043f6f 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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(); @@ -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(); }); } @@ -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(""); diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000..799264e --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +msrv = "1.41.1" diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 4d4ece1..2cc5f0e 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -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(&self, serializer: S) -> Result where S: $crate::serde::Serializer, diff --git a/src/language/mod.rs b/src/language/mod.rs index 1f5f922..85c2d9b 100644 --- a/src/language/mod.rs +++ b/src/language/mod.rs @@ -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()); } diff --git a/src/lib.rs b/src/lib.rs index 856ffe6..2eb85e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ //! # BIP39 Mnemonic Codes //! -//! https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki +//! //! #![deny(non_upper_case_globals)] @@ -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()); @@ -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 { @@ -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)); } @@ -372,7 +372,7 @@ impl Mnemonic { } } - return Err(Error::AmbiguousLanguages(AmbiguousLanguages(possible))); + Err(Error::AmbiguousLanguages(AmbiguousLanguages(possible))) } /// Determine the language of the mnemonic. @@ -789,9 +789,9 @@ mod tests { ]; for vector in &test_vectors { - let entropy = Vec::::from_hex(&vector.0).unwrap(); + let entropy = Vec::::from_hex(vector.0).unwrap(); let mnemonic_str = vector.1; - let seed = Vec::::from_hex(&vector.2).unwrap(); + let seed = Vec::::from_hex(vector.2).unwrap(); let mnemonic = Mnemonic::from_entropy(&entropy).unwrap(); @@ -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"))] @@ -1050,10 +1050,10 @@ mod tests { ]; for vector in &vectors { - let entropy = Vec::::from_hex(&vector.0).unwrap(); + let entropy = Vec::::from_hex(vector.0).unwrap(); let mnemonic_str = vector.1; let passphrase = vector.2; - let seed = Vec::::from_hex(&vector.3).unwrap(); + let seed = Vec::::from_hex(vector.3).unwrap(); let mnemonic = Mnemonic::from_entropy_in(Language::Japanese, &entropy).unwrap(); diff --git a/src/pbkdf2.rs b/src/pbkdf2.rs index e7d3375..2caaf7b 100644 --- a/src/pbkdf2.rs +++ b/src/pbkdf2.rs @@ -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(mnemonic: M) -> usize @@ -58,8 +58,8 @@ fn create_hmac_engine(mnemonic: M) -> hmac::HmacEngine 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()) { @@ -83,7 +83,7 @@ fn create_hmac_engine(mnemonic: M) -> hmac::HmacEngine 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 }