From 63271c50f8d4eec2ae7bb3772108cb9675a6b1fd Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 30 Dec 2025 14:38:10 +0200 Subject: [PATCH] feat(web): add ciphertext input constraints --- web/src/components/cipher_form.rs | 73 ++++++++++++++++++++++---- web/style/main.scss | 85 +++++++++++++++++++++++++++---- 2 files changed, 138 insertions(+), 20 deletions(-) diff --git a/web/src/components/cipher_form.rs b/web/src/components/cipher_form.rs index b246e15..168f639 100644 --- a/web/src/components/cipher_form.rs +++ b/web/src/components/cipher_form.rs @@ -1,5 +1,5 @@ use cipher_factory::prelude::*; -use leptos::prelude::*; +use leptos::{prelude::*, tachys::dom::event_target_value}; use std::{str::FromStr, time::Duration}; use strum::IntoEnumIterator; use web_sys::WheelEvent; @@ -22,14 +22,20 @@ pub fn CipherForm(algorithm: Algorithm) -> impl IntoView { set_output(String::new()); let key = key_input.get(); - let text = text_input.get(); + let raw_text = text_input.get(); - if key.is_empty() || text.is_empty() { + if key.is_empty() || raw_text.is_empty() { set_error_msg("Please enter both key and input text.".to_string()); return; } - let context = CipherContext::new(algorithm, mode.get(), key, text, output_fmt.get()); + let final_text = if mode.get() == OperationMode::Decrypt { + format!("0x{raw_text}") + } else { + raw_text + }; + + let context = CipherContext::new(algorithm, mode.get(), key, final_text, output_fmt.get()); match context.process() { Ok(out) => set_output(out), Err(e) => set_error_msg(e.to_string()), @@ -62,7 +68,7 @@ pub fn CipherForm(algorithm: Algorithm) -> impl IntoView { update_output=update_output /> - +