From e4ad766315879e1ff05bb111229f073f8f0ed68e Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Mon, 10 Oct 2022 21:30:02 +0200 Subject: PassFish: Initial Commit Well, that's a lie. But nobody needs to see all the iterations I decided to sweep under the rug. That said, I think the repo is, while not clean, clean enough now, to not be embarrassed by uploading it to github. --- .../passwordmaker/helperthread/mod.rs | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 rust/src/implementation/passwordmaker/helperthread/mod.rs (limited to 'rust/src/implementation/passwordmaker/helperthread/mod.rs') diff --git a/rust/src/implementation/passwordmaker/helperthread/mod.rs b/rust/src/implementation/passwordmaker/helperthread/mod.rs new file mode 100644 index 0000000..7e3b587 --- /dev/null +++ b/rust/src/implementation/passwordmaker/helperthread/mod.rs @@ -0,0 +1,49 @@ +mod message_parsing; +mod hashers; +mod profile_to_domain; +use std::sync::mpsc::{Receiver, SendError}; +use passwordmaker_rs::PasswordMaker; +use profile_to_domain::{convert_hash_algorithm, convert_leet}; +use super::emittingsender::EmittingSender; +use super::thread_messages::{HelperToUi, UiToHelper}; +use message_parsing::receive_and_get_newest_or_important_command; +use hashers::PassFishHashers; + +pub(super) fn run(to_ui : &EmittingSender, from_ui : &Receiver) -> Result<(), SendError>{ + println!("Helper Thread starting up."); + + while let Ok(m) = receive_and_get_newest_or_important_command(from_ui) + { + //m is a product type, because we gather the latest command of each type. Easiest to deal with those would be using a group of ifs. + //for now the number of alternatives is rather small though, so let's match instead. + match m.0 { + UiToHelper::Shutdown => break, + UiToHelper::GeneratePassword(task) => { + + to_ui.send(HelperToUi::GenerationStarted)?; + let hash_algorithm = convert_hash_algorithm(&task.generation_settings.hash_algorithm); + let use_leet = convert_leet(&task.generation_settings.leet); + let characters = &task.generation_settings.characters; + let username = &task.generation_settings.username; + let modifier = &task.generation_settings.modifier; + let password_length = task.generation_settings.password_length as usize; + let suffix = &task.generation_settings.suffix; + let prefix = &task.generation_settings.prefix; + type Pwm<'a> = PasswordMaker<'a, PassFishHashers>; + let pwm = Pwm::new(hash_algorithm, use_leet, characters, username, modifier, password_length, prefix, suffix); + let input = task.input; + let master_password = task.master_password; + let pwm = pwm.map_err(Into::into); + let password = + pwm.and_then(|pwm| pwm.generate(input, master_password).map_err(Into::into)); + + match password { + Ok(password) => to_ui.send(HelperToUi::Generated{password})?, + Err(error) => to_ui.send(HelperToUi::GenerationFailed{ error })?, + } + } + } + } + println!("Helper Thread shutting down."); + Ok(()) +} -- cgit v1.2.3