File: passphrase_config.rs

package info (click to toggle)
rust-chbs 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: makefile: 4
file content (38 lines) | stat: -rw-r--r-- 1,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Passphrase generation with basic configuration
//!
//! This example shows how to use the [`BasicConfig`](config::BasicConfig) structure for
//! configuring how passphrases should be generated. See the [`BasicConfig`](config::BasicConfig)
//! documentation for all available options.
//!
//! Other configuration structures are available in the [`config`](config) module.
//! You may build your own configuration structure with support for converting it into a
//! [`Scheme`](scheme::Scheme) by implementing the [`ToScheme`](scheme::ToScheme) trait.
//!
//! Note that this example prints the generated passphrase in the console,
//! which might not be desired in most situations.

use chbs::{config::BasicConfig, prelude::*, probability::Probability};

fn main() {
    // Build a custom configuration to:
    // - use hyphens as separator
    // - sometimes capitalizes whole passphrase words
    // - sometimes capitalizes the first characters of passphrase words
    // TODO: use the builder instead
    // let config = BasicConfigBuilder::default()
    //     .separator("-")
    //     .capitalize_first(Probability::from(0.33))
    //     .capitalize_words(Probability::half())
    //     .build()
    //     .unwrap();
    let mut config = BasicConfig::default();
    config.words = 8;
    config.separator = "-".into();
    config.capitalize_first = Probability::from(0.33);
    config.capitalize_words = Probability::half();

    let scheme = config.to_scheme();

    println!("Passphrase: {:?}", scheme.generate());
    println!("Entropy: {:?}", scheme.entropy().bits());
}