use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VaultEntry {
pub id: String,
pub ciphertext: Vec<u8>,
pub description: String,
pub created_at: String,
pub tags: Vec<String>,
}
pub trait VaultProvider: Send + Sync {
fn encrypt(&self, plaintext: &[u8], description: &str) -> anyhow::Result<VaultEntry>;
fn decrypt(&self, id: &str) -> anyhow::Result<Vec<u8>>;
fn exists(&self, id: &str) -> bool;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vault_entry_serializes() {
let entry = VaultEntry {
id: "test-123".to_string(),
ciphertext: vec![0xDE, 0xAD, 0xBE, 0xEF],
description: "Test secret".to_string(),
created_at: "2026-01-01T00:00:00Z".to_string(),
tags: vec!["test".to_string()],
};
let json = serde_json::to_string(&entry).unwrap();
let parsed: VaultEntry = serde_json::from_str(&json).unwrap();
assert_eq!(parsed.id, "test-123");
assert_eq!(parsed.ciphertext, vec![0xDE, 0xAD, 0xBE, 0xEF]);
}
}