diff --git a/Cargo.lock b/Cargo.lock index 49a76fc..93aee24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1445,9 +1445,11 @@ dependencies = [ name = "ptth_core" version = "1.2.0" dependencies = [ + "base64", "ctrlc", "futures", "hyper", + "rand", "serde", "thiserror", "tokio", diff --git a/crates/ptth_core/Cargo.toml b/crates/ptth_core/Cargo.toml index 4413722..53a5149 100644 --- a/crates/ptth_core/Cargo.toml +++ b/crates/ptth_core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ptth_core" -version = "1.2.0" +version = "1.3.0" authors = ["Trish"] edition = "2018" license = "AGPL-3.0" @@ -11,9 +11,11 @@ repository = "https://github.com/ReactorScram/ptth" [dependencies] +base64 = "0.13.0" ctrlc = { version = "3.1.8", features = [ "termination" ] } futures = "0.3.7" hyper = "0.14.4" +rand = "0.8.3" serde = {version = "1.0.124", features = ["derive"]} thiserror = "1.0.24" tokio = { version = "1.2.0", features = ["full"] } diff --git a/crates/ptth_core/src/lib.rs b/crates/ptth_core/src/lib.rs index 7c834b7..e694746 100644 --- a/crates/ptth_core/src/lib.rs +++ b/crates/ptth_core/src/lib.rs @@ -20,6 +20,16 @@ pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str> hay.strip_prefix (prefix) } +/// Generates 64 bytes of entropy and returns it as Base64 + +pub fn gen_key () -> String { + use rand::RngCore; + let mut buffer = vec! [0_u8; 64]; + rand::thread_rng ().fill_bytes (&mut buffer); + + base64::encode (&buffer) +} + #[cfg (test)] mod tests { use super::*; diff --git a/crates/ptth_server/Cargo.toml b/crates/ptth_server/Cargo.toml index 29ce534..ca4754d 100644 --- a/crates/ptth_server/Cargo.toml +++ b/crates/ptth_server/Cargo.toml @@ -43,7 +43,7 @@ toml = "0.5.7" uom = "0.30.0" always_equal = { path = "../always_equal", version = "1.0.0" } -ptth_core = { path = "../ptth_core", version = "1.2.0" } +ptth_core = { path = "../ptth_core", version = "1.3.0" } [dev-dependencies] diff --git a/crates/ptth_server/src/bin/ptth_server.rs b/crates/ptth_server/src/bin/ptth_server.rs index 93b5fea..c98e061 100644 --- a/crates/ptth_server/src/bin/ptth_server.rs +++ b/crates/ptth_server/src/bin/ptth_server.rs @@ -48,18 +48,8 @@ pub struct ConfigFile { pub file_server_root: Option , } -/// Generates 64 bytes of entropy and returns it as Base64 - -fn gen_key () -> String { - use rand::RngCore; - let mut buffer = vec! [0_u8; 64]; - rand::thread_rng ().fill_bytes (&mut buffer); - - base64::encode (&buffer) -} - fn gen_and_save_key (path: &Path) -> anyhow::Result <()> { - let api_key = gen_key (); + let api_key = ptth_core::gen_key (); { let mut f = File::create (path)?;