app

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

commit 43ee8f2e10bc26407a365bf14368c7924eb82569
parent ca04fc44c0025114512f0d0edfa49e32fab1997f
Author: triesap <triesap@radroots.dev>
Date:   Sun, 18 Jan 2026 23:27:03 +0000

app-core: add client cipher error map

- add cipher module scaffold to radroots-app-core
- define RadrootsClientCipherError with message mapping
- implement Display/Error for cipher error enum
- cover cipher error messages with unit tests

Diffstat:
Acrates/core/src/cipher/error.rs | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/core/src/cipher/mod.rs | 3+++
Mcrates/core/src/lib.rs | 1+
3 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/crates/core/src/cipher/error.rs b/crates/core/src/cipher/error.rs @@ -0,0 +1,61 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsClientCipherError { + IdbUndefined, + CryptoUndefined, + InvalidCiphertext, + DecryptFailure, +} + +pub type RadrootsClientCipherErrorMessage = &'static str; + +impl RadrootsClientCipherError { + pub const fn message(self) -> RadrootsClientCipherErrorMessage { + match self { + RadrootsClientCipherError::IdbUndefined => "error.client.cipher.idb_undefined", + RadrootsClientCipherError::CryptoUndefined => "error.client.cipher.crypto_undefined", + RadrootsClientCipherError::InvalidCiphertext => "error.client.cipher.invalid_ciphertext", + RadrootsClientCipherError::DecryptFailure => "error.client.cipher.decrypt_failure", + } + } +} + +impl fmt::Display for RadrootsClientCipherError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsClientCipherError {} + +#[cfg(test)] +mod tests { + use super::RadrootsClientCipherError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsClientCipherError::IdbUndefined, + "error.client.cipher.idb_undefined", + ), + ( + RadrootsClientCipherError::CryptoUndefined, + "error.client.cipher.crypto_undefined", + ), + ( + RadrootsClientCipherError::InvalidCiphertext, + "error.client.cipher.invalid_ciphertext", + ), + ( + RadrootsClientCipherError::DecryptFailure, + "error.client.cipher.decrypt_failure", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +} diff --git a/crates/core/src/cipher/mod.rs b/crates/core/src/cipher/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::{RadrootsClientCipherError, RadrootsClientCipherErrorMessage}; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs @@ -1,3 +1,4 @@ #![forbid(unsafe_code)] pub mod crypto; +pub mod cipher;