pub struct WordList { /* private fields */ }
Expand description
A wordlist.
To load a built-in wordlist, checkout the methods on this struct prefixed with builtin_
.
The default wordlist loaded when using default()
uses
builtin_eff_large()
.
A loaded fixed wordlist which may be used as word provider for passphrase generation by
constructing a sampler using sampler
.
It is highly recommended that the worlist contains at least 7776 (65) words to provide enough entropy when uniformly sampling words from it.
Implementations
sourceimpl WordList
impl WordList
sourcepub fn load<P>(path: P) -> Result<Self, WordListError> where
P: AsRef<Path>,
pub fn load<P>(path: P) -> Result<Self, WordListError> where
P: AsRef<Path>,
Load a wordlist from a file.
This loads a wordlist from a file at the given path, and constructs a WordList
.
- Words are splitted by any whitespace (including newlines),
see
char::is_whitespace
- It assumes any non-whitespace character is part of a word
- Whitespaces are omitted the final wordlist
- Emtpy items are omitted
- The file must not include dice numbers
For wordlists that include dice numbers, the load_diced
method
may be used instead.
If words are separated in a different manner, manually load each word and use the
new
constructor instead.
An error is returned if loading the wordlist failed, or if the loaded file didn’t contain any words.
File examples
abacus abdomen abdominal abide abiding
or
abacus
abdomen
sourcepub fn load_diced<P>(path: P) -> Result<Self, WordListError> where
P: AsRef<Path>,
pub fn load_diced<P>(path: P) -> Result<Self, WordListError> where
P: AsRef<Path>,
Load a diced wordlist from a file.
This loads a diced wordlist from a file at the given path, and constructs a WordList
.
Many diceware wordlists include dice numbers for each word, these should be omitted when
using this crate. This method helps with that.
- Words are splitted by the newline character (
\n
). - Only the last word on each line is kept, terminated by any whitespace, see
char::is_whitespace
- It assumes any non-whitespace character is part of a word
- Prefixed words do not have to be dice numbers
- Lines having a single word with no dice number prefix are included
- Emtpy lines are omitted
For wordlists that do not include dice numbers, the the regular load
method instead.
If words are separated in a different manner, manually load each word and use the
new
constructor instead.
An error is returned if loading the wordlist failed, or if the loaded file didn’t contain any words.
File examples
11111 abacus
11112 abdomen
11113 abdominal
or
#1 (1,1,1,1,2) abacus
#2 (1,1,1,1,2) abdomen
sourcepub fn builtin_eff_large() -> Self
pub fn builtin_eff_large() -> Self
Construct wordlist from built-in EFF large.
Use the built-in EFF large list of words, and construct a wordlist from it.
This is based on BUILTIN_EFF_LARGE
.
sourcepub fn builtin_eff_short() -> Self
pub fn builtin_eff_short() -> Self
Construct wordlist from built-in EFF short.
Use the built-in EFF short list of words, and construct a wordlist from it.
This is based on BUILTIN_EFF_SHORT
.
Note: this wordlist is considered short, as it only contains 1296 (64)
words.
The list has an entropy of about 10.3 bits when uniformly sampling words from it.
It is recommended to use a larger wordlist such as
builtin_eff_large
.
sourcepub fn builtin_eff_general_short() -> Self
pub fn builtin_eff_general_short() -> Self
Construct wordlist from built-in EFF general short.
Use the built-in EFF general short list of words, and construct a wordlist from it.
This is based on BUILTIN_EFF_GENERAL_SHORT
.
Note: this wordlist is considered short, as it only contains 1296 (64)
words.
The list has an entropy of about 10.3 bits when uniformly sampling words from it.
It is recommended to use a larger wordlist such as
builtin_eff_large
.
sourcepub fn sampler(&self) -> WordSampler
pub fn sampler(&self) -> WordSampler
Build a sampler for this wordlist.
The word sampler may be used to pull any number of random words from the wordlist for passphrase generation.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for WordList
impl Send for WordList
impl Sync for WordList
impl Unpin for WordList
impl UnwindSafe for WordList
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more