diff --git a/cipher-core/src/error.rs b/cipher-core/src/error.rs index ac22771..84e8031 100644 --- a/cipher-core/src/error.rs +++ b/cipher-core/src/error.rs @@ -4,15 +4,15 @@ use thiserror::Error; #[derive(Debug, Error, Clone, PartialEq, Eq)] pub enum CipherError { /// Invalid key size for the cipher - #[error("Invalid key size: expected {expected} bytes, got {actual}")] + #[error("Invalid key size: expected {expected} bytes, got {actual}.")] InvalidKeySize { expected: usize, actual: usize }, /// Input data doesn't match the cipher's block size - #[error("Invalid block size: expected {expected} bytes, got {actual}")] + #[error("Invalid block size: expected {expected} bytes, got {actual}.")] InvalidBlockSize { expected: usize, actual: usize }, /// Error parsing block from string - #[error("Error parsing block from string: {0}")] + #[error("{0}")] BlockParseError(#[from] BlockError), } diff --git a/web/src/components/cipher_form.rs b/web/src/components/cipher_form.rs index 92bd290..b246e15 100644 --- a/web/src/components/cipher_form.rs +++ b/web/src/components/cipher_form.rs @@ -50,6 +50,65 @@ pub fn CipherForm(algorithm: Algorithm) -> impl IntoView { } }; + view! { +
+
+

{algorithm.to_string()}

+
+ + + + + + + + + +
+ } +} + +#[component] +fn RadioButton( + value: OperationMode, + current: ReadSignal, + set_current: WriteSignal, +) -> impl IntoView { + view! { +
+ +
+ } +} + +#[component] +fn ConfigurationSection( + mode: ReadSignal, + set_mode: WriteSignal, + output_fmt: ReadSignal, + update_output: impl Fn(OutputFormat) + Copy + Send + 'static, +) -> impl IntoView { let handle_format_change = move |ev| { let val = event_target_value(&ev); let fmt = OutputFormat::from_str(&val).unwrap_or_default(); @@ -76,137 +135,122 @@ pub fn CipherForm(algorithm: Algorithm) -> impl IntoView { }; view! { -
-
-

{algorithm.to_string()}

-
- -
- -
-
- - -
- {move || { - if mode.get() != OperationMode::Decrypt { - return view! { }.into_any(); - } - view! { -
-
- - -
-
- } - .into_any() - }} +
+ +
+
+ +
-
-
- - -
-
- - -
- - - - // Output Section - {move || { - if output.get().is_empty() { - return view! { }.into_any(); - } - view! { -
-
- "Output ("{output_fmt.get().to_string()}")" - + {move || { + if mode.get() != OperationMode::Decrypt { + return view! { }.into_any(); + } + view! { +
+
+ + +
- {output.get()} -
- } - .into_any() - }} - - // Error Section - {move || { - if error_msg.get().is_empty() { - return view! { }.into_any(); - } - view! {
{error_msg.get()}
}.into_any() - }} + } + .into_any() + }} +
} } #[component] -fn RadioButton( - value: OperationMode, - current: ReadSignal, - set_current: WriteSignal, -) -> impl IntoView { +fn KeyInput(set_key_input: WriteSignal) -> impl IntoView { view! { -
- +
+ +
} } + +#[component] +fn TextInput( + mode: ReadSignal, + set_text_input: WriteSignal, +) -> impl IntoView { + view! { +
+ + +
+ } +} + +#[component] +fn OutputBox( + output: ReadSignal, + output_fmt: ReadSignal, + copy_to_clipboard: impl Fn(String) + Copy + Send + 'static, + copy_feedback: ReadSignal, +) -> impl IntoView { + view! { + {move || { + if output.get().is_empty() { + return view! { }.into_any(); + } + view! { +
+
+ "Output ("{output_fmt.get().to_string()}")" + +
+ {output.get()} +
+ } + .into_any() + }} + } +} + +#[component] +fn ErrorBox(error_msg: ReadSignal) -> impl IntoView { + view! { + {move || { + if error_msg.get().is_empty() { + return view! { }.into_any(); + } + view! {
{error_msg.get()}
}.into_any() + }} + } +}