keyfork-mnemonic-util: make clippy happy

This commit is contained in:
Ryan Heywood 2024-01-06 23:20:19 -05:00
parent 91a6b845ba
commit b5d2244091
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 8 additions and 3 deletions

View File

@ -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<Wordlist>) -> Mnemonic {
Mnemonic {
entropy: bytes.to_vec(),