♻️ refactor: move gen_key up to ptth_core
							parent
							
								
									240cd8dff1
								
							
						
					
					
						commit
						3408feb619
					
				|  | @ -1445,9 +1445,11 @@ dependencies = [ | |||
| name = "ptth_core" | ||||
| version = "1.2.0" | ||||
| dependencies = [ | ||||
|  "base64", | ||||
|  "ctrlc", | ||||
|  "futures", | ||||
|  "hyper", | ||||
|  "rand", | ||||
|  "serde", | ||||
|  "thiserror", | ||||
|  "tokio", | ||||
|  |  | |||
|  | @ -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"] } | ||||
|  |  | |||
|  | @ -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::*; | ||||
|  |  | |||
|  | @ -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] | ||||
| 
 | ||||
|  |  | |||
|  | @ -48,18 +48,8 @@ pub struct ConfigFile { | |||
| 	pub file_server_root: Option <PathBuf>, | ||||
| } | ||||
| 
 | ||||
| /// 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)?; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 _
						_