added password generator, added ability to use text file as wordlist
This commit is contained in:
parent
8c049c4790
commit
edc25af9de
|
@ -1,3 +1,5 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use libduralumin::passphrase_gen::{PassPhraseGenerator, Words};
|
use libduralumin::passphrase_gen::{PassPhraseGenerator, Words};
|
||||||
|
|
||||||
|
@ -17,7 +19,11 @@ struct Opts {
|
||||||
min_word_length: Option<i16>,
|
min_word_length: Option<i16>,
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
count: Option<i16>,
|
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,
|
backend: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +52,7 @@ impl Opts {
|
||||||
enum Backend {
|
enum Backend {
|
||||||
UseAPassPhrase,
|
UseAPassPhrase,
|
||||||
EnglishWords,
|
EnglishWords,
|
||||||
|
File(PathBuf),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
|
@ -56,7 +63,14 @@ impl Backend {
|
||||||
match s.as_ref() {
|
match s.as_ref() {
|
||||||
"useapassphrase" => Some(Backend::UseAPassPhrase),
|
"useapassphrase" => Some(Backend::UseAPassPhrase),
|
||||||
"english" => Some(Backend::EnglishWords),
|
"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());
|
.with_length(opts.words_per_passphrase());
|
||||||
|
|
||||||
let words = match opts.backend() {
|
let words = match opts.backend() {
|
||||||
Some(Backend::UseAPassPhrase) => {
|
Some(Backend::UseAPassPhrase) => Words::from_str(include_str!("../../useapassphrase.txt")),
|
||||||
Words::from_str(include_str!("../../useapassphrase.txt"))
|
Some(Backend::EnglishWords) => Words::from_str(include_str!("../../words_alpha.txt")),
|
||||||
}
|
Some(path) => {
|
||||||
Some(Backend::EnglishWords) => {
|
Words::from_text_file(std::fs::File::open(path).expect("failed to read word list."))
|
||||||
Words::from_str(include_str!("../../words_alpha.txt"))
|
.expect("word list from path.")
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
panic!("invalid backend.")
|
panic!("invalid backend.")
|
||||||
|
|
Loading…
Reference in a new issue