rusty-diceware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b1ef5ef2155b3f0cacfc45ccaed1619f010de619
parent 5d9ade5c71b67b1ebe74e8d6aae4cfffe4f36775
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Fri, 16 Sep 2022 22:57:48 +0300

Add a new option. Start obsoleting the literal wordlist flags.

Diffstat:
MCHANGELOG.md | 5+++++
MCargo.toml | 2+-
MREADME.md | 21+++++++++++++++++++++
Msrc/bin/diceware.rs | 112++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
4 files changed, 110 insertions(+), 30 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.4.0 + +* Add the `-l` / `--wordlist` option. +* Warn that the `--beale` / `--reinhold` / `--minilock` flags would be deprecated in the next minor version. + ## v0.3.9 * Move some code from main function to its own function in `src/lib.rs`. diff --git a/Cargo.toml b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diceware" -version = "0.3.9" +version = "0.4.0" authors = ["Yuval Langer <yuvallangerontheroad@gmail.com>"] license = "AGPL-3.0" repository = "https://gitlab.com/yuvallanger/rusty-diceware" diff --git a/README.md b/README.md @@ -15,6 +15,27 @@ Monroe’s [xkcd#936][xkcd-936]: ![“Hidden” alt text jokes are a pain in the ass.](/bin/imgs.xkcd.com/comics/password_strength.png) +## Usage: + +``` +Usage: diceware [options] + +Options: + -h, --help this help message + --minilock [OBSOLETE] use the MiniLock wordlist (default) + --reinhold [OBSOLETE] use the standard wordlist + --beale [OBSOLETE] use the beale wordlist + -e, --entropy display number of entropy bits + -n, --nword NWORD number of words in a passphrase + -d, --delimiter DELIM + the delimiter character used to separate the words + -f, --wordlist-file FILE + path to a wordlist file + -l, --wordlist WORDLIST + Wordlist to use (minilock (default), reinhold, or + beale) +``` + ## Featuring * The original [Reinhold wordlist][reinhold-wordlist-asc] ([Wayback Machine diff --git a/src/bin/diceware.rs b/src/bin/diceware.rs @@ -15,9 +15,13 @@ use diceware::wordlists::REINHOLD_WORDLIST; fn make_options() -> Options { let mut opts = Options::new(); opts.optflag("h", "help", "this help message"); - opts.optflag("", "minilock", "use the MiniLock wordlist (default)"); - opts.optflag("", "reinhold", "use the standard wordlist"); - opts.optflag("", "beale", "use the beale wordlist"); + opts.optflag( + "", + "minilock", + "[OBSOLETE] use the MiniLock wordlist (default)", + ); + opts.optflag("", "reinhold", "[OBSOLETE] use the standard wordlist"); + opts.optflag("", "beale", "[OBSOLETE] use the beale wordlist"); opts.optflag("e", "entropy", "display number of entropy bits"); opts.optopt("n", "nword", "number of words in a passphrase", "NWORD"); opts.optopt( @@ -27,7 +31,12 @@ fn make_options() -> Options { "DELIM", ); opts.optopt("f", "wordlist-file", "path to a wordlist file", "FILE"); - //opts.optopt("l", "wordlist", "Wordlist to use (minilock (default), reinhold, or beale)", "WORDLIST"); + opts.optopt( + "l", + "wordlist", + "Wordlist to use (minilock (default), reinhold, or beale)", + "WORDLIST", + ); opts } @@ -36,6 +45,14 @@ fn print_usage(program: &str, opts: Options) { print!("{}", opts.usage(&brief)); } +fn unknown_wordlist(wordlist_name: &str) -> ! { + eprintln!( + "Unknown wordlist: {}. Available wordlists: beale, reinhold, or minilock.", + wordlist_name, + ); + exit(-1) +} + fn main() { let args: Vec<String> = std::env::args().collect(); let program = &args[0]; @@ -66,6 +83,36 @@ fn main() { let is_entropy_printed = matches.opt_present("entropy"); + let is_reinhold_flag: bool = matches.opt_present("reinhold"); + let is_beale_flag: bool = matches.opt_present("beale"); + let is_minilock_flag: bool = matches.opt_present("minilock"); + let is_wordlist_flag: bool = is_reinhold_flag | is_beale_flag | is_minilock_flag; + + if is_wordlist_flag { + eprintln!("WARNING! The --reinhold, --beale and --minilock flags are deprecated and will be removed in the next minor version release. Use the -l or --wordlist flags instead."); + }; + + let wordlist_name = if let Some(wordlist_option) = matches.opt_str("l") { + if is_wordlist_flag { + eprintln!("ERROR! The --reinhold, --beale, and --minilock flags cannot be used together with the -l or --wordlist flags."); + exit(-1); + } + match wordlist_option.to_lowercase().as_ref() { + z @ ("beale" | "reinhold" | "minilock") => z, + _ => unknown_wordlist(&wordlist_option), + } + .to_string() + } else { + if is_reinhold_flag { + "reinhold" + } else if is_beale_flag { + "beale" + } else { + "minilock" + } + .to_string() + }; + let mut rng = thread_rng(); if word_num != 0 { @@ -85,30 +132,37 @@ fn main() { &is_entropy_printed, &mut rng, ); - } else if matches.opt_present("reinhold") { - print_words( - REINHOLD_WORDLIST.as_ref(), - &word_num, - &delimiter, - &is_entropy_printed, - &mut rng, - ); - } else if matches.opt_present("beale") { - print_words( - BEALE_WORDLIST.as_ref(), - &word_num, - &delimiter, - &is_entropy_printed, - &mut rng, - ); } else { - print_words( - MINILOCK_WORDLIST.as_ref(), - &word_num, - &delimiter, - &is_entropy_printed, - &mut rng, - ); - } - } + match wordlist_name.as_ref() { + "reinhold" => { + print_words( + REINHOLD_WORDLIST.as_ref(), + &word_num, + &delimiter, + &is_entropy_printed, + &mut rng, + ); + } + "beale" => { + print_words( + BEALE_WORDLIST.as_ref(), + &word_num, + &delimiter, + &is_entropy_printed, + &mut rng, + ); + } + "minilock" => { + print_words( + MINILOCK_WORDLIST.as_ref(), + &word_num, + &delimiter, + &is_entropy_printed, + &mut rng, + ); + } + _ => unknown_wordlist(&wordlist_name), + } + }; + }; }