♻️ refactor: use ptth_diceware for the diceware command in ptth_multi_call_server

main
_ 2022-10-16 19:59:06 +00:00
parent 5d560b91de
commit 57d6086ea7
8 changed files with 46 additions and 1317 deletions

1
Cargo.lock generated
View File

@ -1251,6 +1251,7 @@ dependencies = [
"ctrlc",
"futures-util",
"hex",
"ptth_diceware",
"ptth_file_server",
"ptth_quic",
"ptth_server",

View File

@ -1,4 +1,5 @@
[package]
description = "A diceware passphrase generator with 1,200 words, only depends on `rand`"
name = "ptth_diceware"
version = "0.1.0"
edition = "2021"

View File

@ -0,0 +1,41 @@
use rand::Rng;
pub fn main () {
let diceware = Diceware::default ();
let random_words: Vec <&str> = (0..8)
.map (|_| diceware.random_word ())
.collect ();
let passphrase = random_words.join (" ");
println! ("{}", passphrase);
}
pub struct Diceware {
words: Vec <String>,
}
impl Default for Diceware {
fn default () -> Self
{
let wordlist = include_str! ("eff_short_wordlist_1.txt");
let words: Vec <_> = wordlist.split ('\n').take (1253).map (str::to_string).collect ();
assert_eq! (words.len (), 1253);
assert_eq! (words [0], "acid");
assert_eq! (words [600], "large");
assert_eq! (words [1252], "zoom");
Self {
words,
}
}
}
impl Diceware {
pub fn random_word (&self) -> &str
{
&self.words [rand::thread_rng ().gen_range (0..self.words.len ())]
}
}

View File

@ -1,41 +1,3 @@
use rand::Rng;
pub fn main () {
let diceware = Diceware::default ();
let random_words: Vec <&str> = (0..8)
.map (|_| diceware.random_word ())
.collect ();
let passphrase = random_words.join (" ");
println! ("{}", passphrase);
}
pub struct Diceware {
words: Vec <String>,
}
impl Default for Diceware {
fn default () -> Self
{
let wordlist = include_str! ("eff_short_wordlist_1.txt");
let words: Vec <_> = wordlist.split ('\n').take (1253).map (str::to_string).collect ();
assert_eq! (words.len (), 1253);
assert_eq! (words [0], "acid");
assert_eq! (words [600], "large");
assert_eq! (words [1252], "zoom");
Self {
words,
}
}
}
impl Diceware {
pub fn random_word (&self) -> &str
{
&self.words [rand::thread_rng ().gen_range (0..self.words.len ())]
}
ptth_diceware::main ()
}

View File

@ -16,6 +16,7 @@ anyhow = "1.0.38"
ctrlc = "3.2.1"
futures-util = "0.3.9"
hex = "0.4.3"
ptth_diceware = { path = "../ptth_diceware" }
ptth_file_server = { path = "../ptth_file_server_bin" }
ptth_server = { path = "../ptth_server" }
ptth_quic = { path = "../ptth_quic" }

View File

@ -1,23 +0,0 @@
use rand::Rng;
pub fn main () {
let wordlist = include_str! ("eff_short_wordlist_1.txt");
let words: Vec <_> = wordlist.split ('\n').take (1253).collect ();
assert_eq! (words.len (), 1253);
assert_eq! (words [0], "acid");
assert_eq! (words [600], "large");
assert_eq! (words [1252], "zoom");
let mut rng = rand::thread_rng ();
let random_words: Vec <&str> = (0..8)
.map (|_| {
words [rng.gen_range (0..words.len ())]
})
.collect ();
let passphrase = random_words.join (" ");
println! ("{}", passphrase);
}

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@ use std::{
use tokio::sync::watch;
mod diceware;
mod download;
mod ulid;
@ -30,7 +29,7 @@ async fn main () -> anyhow::Result <()> {
let (subcommand, args) = parse_args (&args)?;
match subcommand {
Diceware => {
diceware::main ();
ptth_diceware::main ();
Ok (())
},
Download => download::main (args).await,