app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 32fae2cca8237aed6c17fb6076deaeb859e9a5d7
parent 7b07f5abe8f9ed4b97f0723a6ccf34d53c330353
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:
Mcrates/core/src/cipher/mod.rs | 8++++++++
Acrates/core/src/cipher/types.rs | 42++++++++++++++++++++++++++++++++++++++++++
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()); + } +}