use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use zeroize::Zeroizing;
use crate::wallet::storage::{constants::default_storage_path, StorageKind};
#[cfg(feature = "storage")]
#[cfg_attr(docsrs, doc(cfg(feature = "storage")))]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StorageOptions {
pub(crate) path: PathBuf,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) encryption_key: Option<Zeroizing<[u8; 32]>>,
pub(crate) kind: StorageKind,
}
#[cfg(feature = "storage")]
impl Default for StorageOptions {
fn default() -> Self {
Self {
path: default_storage_path().into(),
encryption_key: None,
kind: StorageKind::default(),
}
}
}
impl StorageOptions {
pub fn new(path: PathBuf, kind: StorageKind) -> Self {
Self {
path,
encryption_key: None,
kind,
}
}
pub fn with_encryption_key(mut self, encryption_key: [u8; 32]) -> Self {
self.encryption_key = Some(Zeroizing::new(encryption_key));
self
}
pub fn path(&self) -> &Path {
&self.path
}
pub fn encryption_key(&self) -> Option<&[u8; 32]> {
self.encryption_key.as_deref()
}
pub fn kind(&self) -> StorageKind {
self.kind
}
}