From b5d22440918398e3f413d7abec98a00fa450cc13 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 6 Jan 2024 23:20:19 -0500 Subject: [PATCH] keyfork-mnemonic-util: make clippy happy --- keyfork-mnemonic-util/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/keyfork-mnemonic-util/src/lib.rs b/keyfork-mnemonic-util/src/lib.rs index b6a1bb2..e7b807f 100644 --- a/keyfork-mnemonic-util/src/lib.rs +++ b/keyfork-mnemonic-util/src/lib.rs @@ -126,7 +126,7 @@ impl Display for Mnemonic { .filter_map(|word| self.wordlist.get_word(word)) .peekable(); while let Some(word) = iter.next() { - f.write_str(&word)?; + f.write_str(word)?; if iter.peek().is_some() { f.write_str(" ")?; } @@ -180,7 +180,7 @@ impl FromStr for Mnemonic { let word = wordlist .0 .iter() - .position(|w| &w == word) + .position(|w| w == word) .ok_or(MnemonicFromStrError::InvalidWord(index))?; usize_words.push(word); for bit in 0..11 { @@ -211,7 +211,7 @@ impl FromStr for Mnemonic { let hash = hasher.finalize().to_vec(); for (i, bit) in checksum_bits.iter().enumerate() { - if !hash[i / 8] & (1 << (7 - (i % 8))) == *bit as u8 { + if !hash[i / 8] & (1 << (7 - (i % 8))) == u8::from(*bit) { return Err(MnemonicFromStrError::InvalidChecksum); } } @@ -246,6 +246,11 @@ impl Mnemonic { Ok(unsafe { Self::from_raw_entropy(bytes, wordlist) }) } + /// # Safety + /// + /// This function can potentially produce mnemonics that are not BIP-0039 compliant or can't + /// properly be encoded as a mnemonic. It is assumed the caller asserts the byte count is `% 4 + /// == 0`. pub unsafe fn from_raw_entropy(bytes: &[u8], wordlist: Arc) -> Mnemonic { Mnemonic { entropy: bytes.to_vec(),