use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::Value; use uuid::Uuid; #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum CipherType { Login, ApiKey, SecureNote, SshKey, Identity, Card, } impl CipherType { pub fn as_str(&self) -> &'static str { match self { Self::Login => "login", Self::ApiKey => "api_key", Self::SecureNote => "secure_note", Self::SshKey => "ssh_key", Self::Identity => "identity", Self::Card => "card", } } pub fn parse(input: &str) -> Self { match input { "login" => Self::Login, "api_key" => Self::ApiKey, "secure_note" => Self::SecureNote, "ssh_key" => Self::SshKey, "identity" => Self::Identity, "card" => Self::Card, _ => Self::SecureNote, } } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct CustomField { pub name: String, pub value: Value, #[serde(default)] pub sensitive: bool, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct LoginPayload { #[serde(default)] pub username: Option, #[serde(default)] pub uris: Vec, #[serde(default)] pub password: Option, #[serde(default)] pub totp: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct ApiKeyPayload { #[serde(default)] pub client_id: Option, #[serde(default)] pub secret: Option, #[serde(default)] pub base_url: Option, #[serde(default)] pub host: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct SecureNotePayload { #[serde(default)] pub text: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct SshKeyPayload { #[serde(default)] pub username: Option, #[serde(default)] pub host: Option, #[serde(default)] pub port: Option, #[serde(default)] pub private_key: Option, #[serde(default)] pub passphrase: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(tag = "kind", rename_all = "snake_case")] pub enum ItemPayload { Login(LoginPayload), ApiKey(ApiKeyPayload), SecureNote(SecureNotePayload), SshKey(SshKeyPayload), } impl Default for ItemPayload { fn default() -> Self { Self::SecureNote(SecureNotePayload::default()) } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct CipherView { pub id: Uuid, pub cipher_type: CipherType, pub name: String, pub folder: String, #[serde(default)] pub notes: Option, #[serde(default)] pub custom_fields: Vec, #[serde(default)] pub deleted_at: Option>, pub revision_date: DateTime, pub payload: ItemPayload, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Cipher { pub id: Uuid, pub user_id: Uuid, pub object_kind: String, pub cipher_type: CipherType, pub revision: i64, pub cipher_version: i32, pub ciphertext: Vec, pub content_hash: String, pub deleted_at: Option>, pub created_at: DateTime, pub updated_at: DateTime, }