♻️ refactor: use ptth_diceware for the diceware command in ptth_multi_call_server
parent
5d560b91de
commit
57d6086ea7
|
@ -1251,6 +1251,7 @@ dependencies = [
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hex",
|
"hex",
|
||||||
|
"ptth_diceware",
|
||||||
"ptth_file_server",
|
"ptth_file_server",
|
||||||
"ptth_quic",
|
"ptth_quic",
|
||||||
"ptth_server",
|
"ptth_server",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
|
description = "A diceware passphrase generator with 1,200 words, only depends on `rand`"
|
||||||
name = "ptth_diceware"
|
name = "ptth_diceware"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
|
@ -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 ())]
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,41 +1,3 @@
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
pub fn main () {
|
pub fn main () {
|
||||||
let diceware = Diceware::default ();
|
ptth_diceware::main ()
|
||||||
|
|
||||||
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 ())]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ anyhow = "1.0.38"
|
||||||
ctrlc = "3.2.1"
|
ctrlc = "3.2.1"
|
||||||
futures-util = "0.3.9"
|
futures-util = "0.3.9"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
ptth_diceware = { path = "../ptth_diceware" }
|
||||||
ptth_file_server = { path = "../ptth_file_server_bin" }
|
ptth_file_server = { path = "../ptth_file_server_bin" }
|
||||||
ptth_server = { path = "../ptth_server" }
|
ptth_server = { path = "../ptth_server" }
|
||||||
ptth_quic = { path = "../ptth_quic" }
|
ptth_quic = { path = "../ptth_quic" }
|
||||||
|
|
|
@ -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
|
@ -5,7 +5,6 @@ use std::{
|
||||||
|
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
mod diceware;
|
|
||||||
mod download;
|
mod download;
|
||||||
mod ulid;
|
mod ulid;
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ async fn main () -> anyhow::Result <()> {
|
||||||
let (subcommand, args) = parse_args (&args)?;
|
let (subcommand, args) = parse_args (&args)?;
|
||||||
match subcommand {
|
match subcommand {
|
||||||
Diceware => {
|
Diceware => {
|
||||||
diceware::main ();
|
ptth_diceware::main ();
|
||||||
Ok (())
|
Ok (())
|
||||||
},
|
},
|
||||||
Download => download::main (args).await,
|
Download => download::main (args).await,
|
||||||
|
|
Loading…
Reference in New Issue