feat(core): scaffold item_types module with ItemType + ItemCore enum
Stub LoginCore, SecureNoteCore, IdentityCore, CardCore, KeyCore, DocumentCore, TotpCore. Tag-based serde representation with snake_case discriminants. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
15
crates/idfoto-core/src/item_types/card.rs
Normal file
15
crates/idfoto-core/src/item_types/card.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct CardCore {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum CardKind {
|
||||||
|
#[default]
|
||||||
|
Credit,
|
||||||
|
Debit,
|
||||||
|
Gift,
|
||||||
|
Loyalty,
|
||||||
|
Other,
|
||||||
|
}
|
||||||
3
crates/idfoto-core/src/item_types/document.rs
Normal file
3
crates/idfoto-core/src/item_types/document.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct DocumentCore {}
|
||||||
3
crates/idfoto-core/src/item_types/identity.rs
Normal file
3
crates/idfoto-core/src/item_types/identity.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct IdentityCore {}
|
||||||
3
crates/idfoto-core/src/item_types/key.rs
Normal file
3
crates/idfoto-core/src/item_types/key.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct KeyCore {}
|
||||||
3
crates/idfoto-core/src/item_types/login.rs
Normal file
3
crates/idfoto-core/src/item_types/login.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct LoginCore {}
|
||||||
73
crates/idfoto-core/src/item_types/mod.rs
Normal file
73
crates/idfoto-core/src/item_types/mod.rs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
//! Per-type "core" structs for typed items.
|
||||||
|
//!
|
||||||
|
//! Each variant lives in its own submodule. The `ItemCore` enum + match
|
||||||
|
//! exhaustiveness is the extension mechanism — adding a new variant later
|
||||||
|
//! means: create the submodule, add the enum variant, fix the match arms
|
||||||
|
//! the compiler points at, register the popup form (Plan 1C).
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub mod login;
|
||||||
|
pub mod secure_note;
|
||||||
|
pub mod identity;
|
||||||
|
pub mod card;
|
||||||
|
pub mod key;
|
||||||
|
pub mod document;
|
||||||
|
pub mod totp;
|
||||||
|
|
||||||
|
pub use login::LoginCore;
|
||||||
|
pub use secure_note::SecureNoteCore;
|
||||||
|
pub use identity::IdentityCore;
|
||||||
|
pub use card::{CardCore, CardKind};
|
||||||
|
pub use key::KeyCore;
|
||||||
|
pub use document::DocumentCore;
|
||||||
|
pub use totp::{TotpCore, TotpConfig, TotpAlgorithm, TotpKind};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum ItemType {
|
||||||
|
Login,
|
||||||
|
SecureNote,
|
||||||
|
Identity,
|
||||||
|
Card,
|
||||||
|
Key,
|
||||||
|
Document,
|
||||||
|
Totp,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
|
pub enum ItemCore {
|
||||||
|
Login(LoginCore),
|
||||||
|
SecureNote(SecureNoteCore),
|
||||||
|
Identity(IdentityCore),
|
||||||
|
Card(CardCore),
|
||||||
|
Key(KeyCore),
|
||||||
|
Document(DocumentCore),
|
||||||
|
Totp(TotpCore),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ItemCore {
|
||||||
|
pub fn item_type(&self) -> ItemType {
|
||||||
|
match self {
|
||||||
|
ItemCore::Login(_) => ItemType::Login,
|
||||||
|
ItemCore::SecureNote(_) => ItemType::SecureNote,
|
||||||
|
ItemCore::Identity(_) => ItemType::Identity,
|
||||||
|
ItemCore::Card(_) => ItemType::Card,
|
||||||
|
ItemCore::Key(_) => ItemType::Key,
|
||||||
|
ItemCore::Document(_) => ItemType::Document,
|
||||||
|
ItemCore::Totp(_) => ItemType::Totp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn item_type_serializes_snake_case() {
|
||||||
|
let json = serde_json::to_string(&ItemType::SecureNote).unwrap();
|
||||||
|
assert_eq!(json, "\"secure_note\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
3
crates/idfoto-core/src/item_types/secure_note.rs
Normal file
3
crates/idfoto-core/src/item_types/secure_note.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct SecureNoteCore {}
|
||||||
28
crates/idfoto-core/src/item_types/totp.rs
Normal file
28
crates/idfoto-core/src/item_types/totp.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct TotpCore {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct TotpConfig {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum TotpAlgorithm {
|
||||||
|
#[default]
|
||||||
|
Sha1,
|
||||||
|
Sha256,
|
||||||
|
Sha512,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum TotpKind {
|
||||||
|
Totp,
|
||||||
|
Hotp { counter: u64 },
|
||||||
|
Steam,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for TotpKind {
|
||||||
|
fn default() -> Self { TotpKind::Totp }
|
||||||
|
}
|
||||||
@@ -41,6 +41,9 @@ pub use ids::{AttachmentId, FieldId, ItemId};
|
|||||||
pub mod time;
|
pub mod time;
|
||||||
pub use time::{now_unix, MonthYear};
|
pub use time::{now_unix, MonthYear};
|
||||||
|
|
||||||
|
pub mod item_types;
|
||||||
|
pub use item_types::{ItemCore, ItemType};
|
||||||
|
|
||||||
pub mod crypto;
|
pub mod crypto;
|
||||||
pub use crypto::{decrypt, derive_master_key, encrypt, KdfParams};
|
pub use crypto::{decrypt, derive_master_key, encrypt, KdfParams};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user