refactor: clean up encryption/decryption

This commit is contained in:
2025-03-07 17:43:15 -05:00
parent 14e3781e05
commit 73e7e17da4
2 changed files with 12 additions and 12 deletions

View File

@@ -28,15 +28,16 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
if let Some(sender) = sender {
let mut ncr_options = None;
if let (Ok(options), Ok(decrypt)) = (
globals.get::<Table>("NcrOptions"),
globals.get::<Function>("ncr_decrypt"),
) && let Ok(decrypted) =
decrypt.call::<String>((options.clone(), content.clone()))
&& let Ok(trimmed) = trim_header(&decrypted)
if let Ok(options) = globals.get::<Table>("NcrOptions")
&& let Ok(decrypt) = globals.get::<Function>("ncr_decrypt")
&& let Some(plaintext) = decrypt
.call::<String>((options.clone(), content.clone()))
.ok()
.as_deref()
.and_then(|s| trim_header(s).ok())
{
ncr_options = Some(options);
trimmed.clone_into(&mut content);
plaintext.clone_into(&mut content);
info!("decrypted message from {sender}: {content}");
}