use vapkey::Password;
use std::path::{PathBuf};
use {SafeAccount, Error};
mod disk;
mod memory;
mod vault;
#[derive(Debug)]
pub enum SetKeyError {
Fatal(Error),
NonFatalOld(Error),
NonFatalNew(Error),
}
#[derive(Clone, PartialEq, Eq)]
pub struct VaultKey {
pub password: Password,
pub iterations: u32,
}
pub trait KeyDirectory: Send + Sync {
fn load(&self) -> Result<Vec<SafeAccount>, Error>;
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
fn remove(&self, account: &SafeAccount) -> Result<(), Error>;
fn path(&self) -> Option<&PathBuf> { None }
fn as_vault_provider(&self) -> Option<&dyn VaultKeyDirectoryProvider> { None }
fn unique_repr(&self) -> Result<u64, Error>;
}
pub trait VaultKeyDirectoryProvider {
fn create(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error>;
fn open(&self, name: &str, key: VaultKey) -> Result<Box<dyn VaultKeyDirectory>, Error>;
fn list_vaults(&self) -> Result<Vec<String>, Error>;
fn vault_meta(&self, name: &str) -> Result<String, Error>;
}
pub trait VaultKeyDirectory: KeyDirectory {
fn as_key_directory(&self) -> &dyn KeyDirectory;
fn name(&self) -> &str;
fn key(&self) -> VaultKey;
fn set_key(&self, key: VaultKey) -> Result<(), SetKeyError>;
fn meta(&self) -> String;
fn set_meta(&self, meta: &str) -> Result<(), Error>;
}
pub use self::disk::{RootDiskDirectory, DiskKeyFileManager, KeyFileManager};
pub use self::memory::MemoryDirectory;
pub use self::vault::VaultDiskDirectory;
impl VaultKey {
pub fn new(password: &Password, iterations: u32) -> Self {
VaultKey {
password: password.clone(),
iterations: iterations,
}
}
}