commit ca04fc44c0025114512f0d0edfa49e32fab1997f
parent 3fab7683705d6ef219b384385d18e8b3b10efea0
Author: triesap <triesap@radroots.dev>
Date: Sun, 18 Jan 2026 23:24:28 +0000
app-core: add client crypto error map
- add radroots-app-core crate with crypto module scaffold
- define RadrootsClientCryptoError and message mapping
- cover error message strings with unit tests
- register new crate in workspace members
Diffstat:
7 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -27,4 +27,6 @@ justfile
# dev
*dev*.toml
-*dev*.json
-\ No newline at end of file
+*dev*.json
+
+refs
+\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
@@ -1146,6 +1146,10 @@ dependencies = [
]
[[package]]
+name = "radroots-app-core"
+version = "0.1.0"
+
+[[package]]
name = "reactive_graph"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -1,6 +1,7 @@
[workspace]
members = [
- "app"
+ "app",
+ "crates/core"
]
resolver = "2"
diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "radroots-app-core"
+authors = ["Radroots Authors"]
+version.workspace = true
+edition.workspace = true
+license.workspace = true
+rust-version.workspace = true
+
+[lib]
+crate-type = ["rlib"]
diff --git a/crates/core/src/crypto/error.rs b/crates/core/src/crypto/error.rs
@@ -0,0 +1,109 @@
+use std::fmt;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RadrootsClientCryptoError {
+ IdbUndefined,
+ CryptoUndefined,
+ InvalidEnvelope,
+ InvalidKeyId,
+ KeyNotFound,
+ UnwrapFailure,
+ WrapFailure,
+ LegacyKeyMissing,
+ EncryptFailure,
+ DecryptFailure,
+ KdfFailure,
+ RegistryFailure,
+}
+
+pub type RadrootsClientCryptoErrorMessage = &'static str;
+
+impl RadrootsClientCryptoError {
+ pub const fn message(self) -> RadrootsClientCryptoErrorMessage {
+ match self {
+ RadrootsClientCryptoError::IdbUndefined => "error.client.crypto.idb_undefined",
+ RadrootsClientCryptoError::CryptoUndefined => "error.client.crypto.crypto_undefined",
+ RadrootsClientCryptoError::InvalidEnvelope => "error.client.crypto.invalid_envelope",
+ RadrootsClientCryptoError::InvalidKeyId => "error.client.crypto.invalid_key_id",
+ RadrootsClientCryptoError::KeyNotFound => "error.client.crypto.key_not_found",
+ RadrootsClientCryptoError::UnwrapFailure => "error.client.crypto.unwrap_failure",
+ RadrootsClientCryptoError::WrapFailure => "error.client.crypto.wrap_failure",
+ RadrootsClientCryptoError::LegacyKeyMissing => "error.client.crypto.legacy_key_missing",
+ RadrootsClientCryptoError::EncryptFailure => "error.client.crypto.encrypt_failure",
+ RadrootsClientCryptoError::DecryptFailure => "error.client.crypto.decrypt_failure",
+ RadrootsClientCryptoError::KdfFailure => "error.client.crypto.kdf_failure",
+ RadrootsClientCryptoError::RegistryFailure => "error.client.crypto.registry_failure",
+ }
+ }
+}
+
+impl fmt::Display for RadrootsClientCryptoError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(self.message())
+ }
+}
+
+impl std::error::Error for RadrootsClientCryptoError {}
+
+#[cfg(test)]
+mod tests {
+ use super::RadrootsClientCryptoError;
+
+ #[test]
+ fn message_matches_spec() {
+ let cases = [
+ (
+ RadrootsClientCryptoError::IdbUndefined,
+ "error.client.crypto.idb_undefined",
+ ),
+ (
+ RadrootsClientCryptoError::CryptoUndefined,
+ "error.client.crypto.crypto_undefined",
+ ),
+ (
+ RadrootsClientCryptoError::InvalidEnvelope,
+ "error.client.crypto.invalid_envelope",
+ ),
+ (
+ RadrootsClientCryptoError::InvalidKeyId,
+ "error.client.crypto.invalid_key_id",
+ ),
+ (
+ RadrootsClientCryptoError::KeyNotFound,
+ "error.client.crypto.key_not_found",
+ ),
+ (
+ RadrootsClientCryptoError::UnwrapFailure,
+ "error.client.crypto.unwrap_failure",
+ ),
+ (
+ RadrootsClientCryptoError::WrapFailure,
+ "error.client.crypto.wrap_failure",
+ ),
+ (
+ RadrootsClientCryptoError::LegacyKeyMissing,
+ "error.client.crypto.legacy_key_missing",
+ ),
+ (
+ RadrootsClientCryptoError::EncryptFailure,
+ "error.client.crypto.encrypt_failure",
+ ),
+ (
+ RadrootsClientCryptoError::DecryptFailure,
+ "error.client.crypto.decrypt_failure",
+ ),
+ (
+ RadrootsClientCryptoError::KdfFailure,
+ "error.client.crypto.kdf_failure",
+ ),
+ (
+ RadrootsClientCryptoError::RegistryFailure,
+ "error.client.crypto.registry_failure",
+ ),
+ ];
+ for (err, expected) in cases {
+ assert_eq!(err.message(), expected);
+ assert_eq!(err.to_string(), expected);
+ }
+ }
+}
diff --git a/crates/core/src/crypto/mod.rs b/crates/core/src/crypto/mod.rs
@@ -0,0 +1,3 @@
+pub mod error;
+
+pub use error::{RadrootsClientCryptoError, RadrootsClientCryptoErrorMessage};
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
@@ -0,0 +1,3 @@
+#![forbid(unsafe_code)]
+
+pub mod crypto;