Skip to content

Commit

Permalink
Merge pull request #15 from varovainen/va-2024-04-23-try-word-ref
Browse files Browse the repository at this point in the history
fix: word ref instead of word
  • Loading branch information
Slesarew authored Apr 23, 2024
2 parents 9ff3fe8 + 2760764 commit 56fc336
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait AsWordList {
&self,
prefix: &str,
) -> Result<Vec<WordListElement<Self>>, ErrorWordList>;
fn bits11_for_word(&self, word: Self::Word) -> Result<Bits11, ErrorWordList>;
fn bits11_for_word(&self, word: &str) -> Result<Bits11, ErrorWordList>;
}

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -144,7 +144,7 @@ impl WordSet {

pub fn add_word<L: AsWordList>(
&mut self,
word: L::Word,
word: &str,
wordlist: &L,
) -> Result<(), ErrorWordList> {
if self.bits11_set.len() < MAX_SEED_LEN {
Expand Down
2 changes: 1 addition & 1 deletion src/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl AsWordList for InternalWordList {
Ok(out)
}

fn bits11_for_word(&self, word: Self::Word) -> Result<Bits11, ErrorWordList> {
fn bits11_for_word(&self, word: &str) -> Result<Bits11, ErrorWordList> {
for (i, element) in WORDLIST_ENGLISH.iter().enumerate() {
if element == &word {
return Bits11::from(i as u16);
Expand Down
16 changes: 4 additions & 12 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#[cfg(not(feature = "std"))]
use alloc::{
string::{String, ToString},
vec::Vec,
};
use alloc::{string::String, vec::Vec};

#[cfg(feature = "std")]
use std::{
string::{String, ToString},
vec::Vec,
};
use std::{string::String, vec::Vec};

use crate::error::ErrorWordList;

Expand Down Expand Up @@ -61,7 +55,7 @@ impl AsWordList for FlashMockWordList {
Ok(words_by_prefix)
}

fn bits11_for_word(&self, word: Self::Word) -> Result<Bits11, ErrorWordList> {
fn bits11_for_word(&self, word: &str) -> Result<Bits11, ErrorWordList> {
for bits_u16 in 0..TOTAL_WORDS {
let bits11 = Bits11::from(bits_u16 as u16)?;
let read_word = self.get_word(bits11)?;
Expand Down Expand Up @@ -203,9 +197,7 @@ fn flash_mock_phrase_to_entropy() {
let entropy_set = hex::decode(known[1]).unwrap();
let mut word_set = WordSet::new();
for word in known[0].split(' ') {
word_set
.add_word(word.to_string(), &flash_mock_word_list)
.unwrap();
word_set.add_word(word, &flash_mock_word_list).unwrap();
}
let entropy_calc = word_set.to_entropy().unwrap();
assert_eq!(entropy_calc, entropy_set);
Expand Down

0 comments on commit 56fc336

Please sign in to comment.