feat: introduce a non-blocking keygen

* ui can be used normally even while keygen is running; the only thing
  that the program will refuse to do is spin up another instance of
  keygen, of which the user will kindly be informed
* this required some async-await fiddling and running genprimes_handler
  as a Task
This commit is contained in:
surtur 2021-01-12 14:37:17 +01:00
parent a6b87453ff
commit 19ac664b56
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 16 additions and 4 deletions

View File

@ -84,9 +84,14 @@ namespace KRY_0x04
lh.keysize_handler(keysizebutton);
}
private void keygen_button_Click(object sender, EventArgs e)
private async void keygen_button_Click(object sender, EventArgs e)
{
lh.genprimes_handler(threadsbox, label_threads_warning, label_keygen_running);
if (lh.keygen_is_running)
{
MessageBox.Show("keygen is already running!\nsince it's a resource-intensive operation, you can only run one keygen instance at a time", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
await lh.genprimes_handler(threadsbox, label_threads_warning, label_keygen_running);
}
private void threadsbox_TextChanged(object sender, EventArgs e)

View File

@ -2,6 +2,8 @@
using System.IO;
using System.IO.Compression;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KRY_0x04
@ -387,7 +389,8 @@ namespace KRY_0x04
}
internal void genprimes_handler(TextBox threadsbox, Label threads_warning, Label keygen_running)
internal bool keygen_is_running { get; private set; }
internal async Task genprimes_handler(TextBox threadsbox, Label threads_warning, Label keygen_running)
{
MessageBox.Show("in the next step, you will be choosing path for saving the key pair", "info", MessageBoxButtons.OK, MessageBoxIcon.Information);
string path = "";
@ -414,8 +417,12 @@ namespace KRY_0x04
return;
}
keygen_running.Visible = true;
rsapls.genprimes_handler(threadsbox, threads_warning, path);
keygen_running.Update();
keygen_is_running = true;
await Task.Run(() => rsapls.genprimes_handler(threadsbox, threads_warning, path));
keygen_is_running = false;
keygen_running.Visible = false;
keygen_running.Update();
}
}
}