added password generator, added ability to use text file as wordlist

This commit is contained in:
Janis 2022-04-04 14:59:24 +02:00
parent 8c049c4790
commit edc25af9de

View file

@ -1,3 +1,5 @@
use std::path::PathBuf;
use clap::Parser;
use libduralumin::passphrase_gen::{PassPhraseGenerator, Words};
@ -17,7 +19,11 @@ struct Opts {
min_word_length: Option<i16>,
#[clap(short, long)]
count: Option<i16>,
#[clap(long, default_value = "useapassphrase")]
#[clap(
long,
default_value = "useapassphrase",
long_help = "word list to use for passphrase generation, a filepath or any of `useapassphrase`, `english`"
)]
backend: String,
}
@ -46,6 +52,7 @@ impl Opts {
enum Backend {
UseAPassPhrase,
EnglishWords,
File(PathBuf),
}
impl Backend {
@ -56,7 +63,14 @@ impl Backend {
match s.as_ref() {
"useapassphrase" => Some(Backend::UseAPassPhrase),
"english" => Some(Backend::EnglishWords),
_ => None,
_ => {
let path = PathBuf::from(s.as_ref());
if path.exists() {
Some(Backend::File(path))
} else {
None
}
}
}
}
}
@ -69,11 +83,11 @@ fn main() {
.with_length(opts.words_per_passphrase());
let words = match opts.backend() {
Some(Backend::UseAPassPhrase) => {
Words::from_str(include_str!("../../useapassphrase.txt"))
}
Some(Backend::EnglishWords) => {
Words::from_str(include_str!("../../words_alpha.txt"))
Some(Backend::UseAPassPhrase) => Words::from_str(include_str!("../../useapassphrase.txt")),
Some(Backend::EnglishWords) => Words::from_str(include_str!("../../words_alpha.txt")),
Some(path) => {
Words::from_text_file(std::fs::File::open(path).expect("failed to read word list."))
.expect("word list from path.")
}
None => {
panic!("invalid backend.")