pub struct Entropy(/* private fields */);Expand description
Password entropy.
The entropy number used internally represents the number of base 2 entropy bits,
and is calculated using log2(choices).
Implementations§
Source§impl Entropy
impl Entropy
Sourcepub fn from_bits<F: Into<f64>>(bits: F) -> Self
pub fn from_bits<F: Into<f64>>(bits: F) -> Self
Construct entropy from a number of entropy bits.
Sourcepub fn from_real<F: Into<f64>>(real: F) -> Self
pub fn from_real<F: Into<f64>>(real: F) -> Self
Construct entropy from a real number.
For a wordlist of 7776 words where choices are uniform, the real number 7776 may be given
to construct the proper entropy value. This would produce an entropy instance with about
12.9 bits.
If Entropy should be constructed from a number of bits, use
from_bits instead.
Sourcepub fn bits(self) -> f64
pub fn bits(self) -> f64
Get the number of entropy bits.
Examples found in repository?
examples/passphrase_config.rs (line 37)
16fn main() {
17 // Build a custom configuration to:
18 // - use hyphens as separator
19 // - sometimes capitalizes whole passphrase words
20 // - sometimes capitalizes the first characters of passphrase words
21 // TODO: use the builder instead
22 // let config = BasicConfigBuilder::default()
23 // .separator("-")
24 // .capitalize_first(Probability::from(0.33))
25 // .capitalize_words(Probability::half())
26 // .build()
27 // .unwrap();
28 let mut config = BasicConfig::default();
29 config.words = 8;
30 config.separator = "-".into();
31 config.capitalize_first = Probability::from(0.33);
32 config.capitalize_words = Probability::half();
33
34 let scheme = config.to_scheme();
35
36 println!("Passphrase: {:?}", scheme.generate());
37 println!("Entropy: {:?}", scheme.entropy().bits());
38}Trait Implementations§
Source§impl PartialOrd for Entropy
impl PartialOrd for Entropy
impl Copy for Entropy
impl StructuralPartialEq for Entropy
Auto Trait Implementations§
impl Freeze for Entropy
impl RefUnwindSafe for Entropy
impl Send for Entropy
impl Sync for Entropy
impl Unpin for Entropy
impl UnsafeUnpin for Entropy
impl UnwindSafe for Entropy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more