commit 35f6cdfc8168d690f1ad0790a11fe48565e3d702
parent 32ac332abe410ce7bc2ef524ae4610bde066127f
Author: triesap <triesap@radroots.dev>
Date: Mon, 19 Jan 2026 00:45:38 +0000
app-core: add cipher trait and config types
- define cipher result aliases for encrypt/decrypt/reset
- add configurable cipher options for idb and crypto settings
- introduce async cipher trait for client implementations
- add unit test covering default config state
Diffstat:
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/crates/core/src/cipher/mod.rs b/crates/core/src/cipher/mod.rs
@@ -1,3 +1,11 @@
pub mod error;
+pub mod types;
pub use error::{RadrootsClientCipherError, RadrootsClientCipherErrorMessage};
+pub use types::{
+ RadrootsClientCipher,
+ RadrootsClientCipherConfig,
+ RadrootsClientCipherDecryptResult,
+ RadrootsClientCipherEncryptResult,
+ RadrootsClientCipherResetResult,
+};
diff --git a/crates/core/src/cipher/types.rs b/crates/core/src/cipher/types.rs
@@ -0,0 +1,42 @@
+use async_trait::async_trait;
+
+use crate::idb::RadrootsClientIdbConfig;
+
+use super::RadrootsClientCipherError;
+
+pub type RadrootsClientCipherEncryptResult = Result<Vec<u8>, RadrootsClientCipherError>;
+pub type RadrootsClientCipherDecryptResult = Result<Vec<u8>, RadrootsClientCipherError>;
+pub type RadrootsClientCipherResetResult = Result<(), RadrootsClientCipherError>;
+
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct RadrootsClientCipherConfig {
+ pub idb_config: Option<RadrootsClientIdbConfig>,
+ pub key_name: Option<String>,
+ pub key_length: Option<u32>,
+ pub iv_length: Option<u32>,
+ pub algorithm: Option<String>,
+}
+
+#[async_trait(?Send)]
+pub trait RadrootsClientCipher {
+ fn get_config(&self) -> RadrootsClientIdbConfig;
+
+ async fn reset(&self) -> RadrootsClientCipherResetResult;
+ async fn encrypt(&self, data: &[u8]) -> RadrootsClientCipherEncryptResult;
+ async fn decrypt(&self, blob: &[u8]) -> RadrootsClientCipherDecryptResult;
+}
+
+#[cfg(test)]
+mod tests {
+ use super::RadrootsClientCipherConfig;
+
+ #[test]
+ fn default_config_is_empty() {
+ let config = RadrootsClientCipherConfig::default();
+ assert!(config.idb_config.is_none());
+ assert!(config.key_name.is_none());
+ assert!(config.key_length.is_none());
+ assert!(config.iv_length.is_none());
+ assert!(config.algorithm.is_none());
+ }
+}