@@ -1,7 +1,12 @@
|
||||
use enostr::FullKeypair;
|
||||
|
||||
use crate::macos_key_storage::MacOSKeyStorage;
|
||||
|
||||
pub const SERVICE_NAME: &str = "Notedeck";
|
||||
|
||||
pub enum KeyStorage {
|
||||
None,
|
||||
MacOS,
|
||||
// TODO:
|
||||
// Linux,
|
||||
// Windows,
|
||||
@@ -12,6 +17,7 @@ impl KeyStorage {
|
||||
pub fn get_keys(&self) -> Result<Vec<FullKeypair>, KeyStorageError> {
|
||||
match self {
|
||||
Self::None => Ok(Vec::new()),
|
||||
Self::MacOS => Ok(MacOSKeyStorage::new(SERVICE_NAME).get_all_fullkeypairs()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +25,7 @@ impl KeyStorage {
|
||||
let _ = key;
|
||||
match self {
|
||||
Self::None => Ok(()),
|
||||
Self::MacOS => MacOSKeyStorage::new(SERVICE_NAME).add_key(key),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,25 +33,26 @@ impl KeyStorage {
|
||||
let _ = key;
|
||||
match self {
|
||||
Self::None => Ok(()),
|
||||
Self::MacOS => MacOSKeyStorage::new(SERVICE_NAME).delete_key(&key.pubkey),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum KeyStorageError<'a> {
|
||||
pub enum KeyStorageError {
|
||||
Retrieval,
|
||||
Addition(&'a FullKeypair),
|
||||
Removal(&'a FullKeypair),
|
||||
Addition(String),
|
||||
Removal(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyStorageError<'_> {
|
||||
impl std::fmt::Display for KeyStorageError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Retrieval => write!(f, "Failed to retrieve keys."),
|
||||
Self::Addition(key) => write!(f, "Failed to add key: {:?}", key.pubkey),
|
||||
Self::Removal(key) => write!(f, "Failed to remove key: {:?}", key.pubkey),
|
||||
Self::Addition(key) => write!(f, "Failed to add key: {:?}", key),
|
||||
Self::Removal(key) => write!(f, "Failed to remove key: {:?}", key),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for KeyStorageError<'_> {}
|
||||
impl std::error::Error for KeyStorageError {}
|
||||
|
||||
Reference in New Issue
Block a user