mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-06 01:44:21 +01:00
Conditionally compile MacOS key storage code
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -41,6 +41,8 @@ strum = "0.26"
|
||||
strum_macros = "0.26"
|
||||
bitflags = "2.5.0"
|
||||
egui_virtual_list = "0.3.0"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
security-framework = "2.11.0"
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use enostr::FullKeypair;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use crate::macos_key_storage::MacOSKeyStorage;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub const SERVICE_NAME: &str = "Notedeck";
|
||||
|
||||
pub enum KeyStorage {
|
||||
None,
|
||||
#[cfg(target_os = "macos")]
|
||||
MacOS,
|
||||
// TODO:
|
||||
// Linux,
|
||||
@@ -17,6 +20,7 @@ impl KeyStorage {
|
||||
pub fn get_keys(&self) -> Result<Vec<FullKeypair>, KeyStorageError> {
|
||||
match self {
|
||||
Self::None => Ok(Vec::new()),
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::MacOS => Ok(MacOSKeyStorage::new(SERVICE_NAME).get_all_fullkeypairs()),
|
||||
}
|
||||
}
|
||||
@@ -25,6 +29,7 @@ impl KeyStorage {
|
||||
let _ = key;
|
||||
match self {
|
||||
Self::None => Ok(()),
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::MacOS => MacOSKeyStorage::new(SERVICE_NAME).add_key(key),
|
||||
}
|
||||
}
|
||||
@@ -33,6 +38,7 @@ impl KeyStorage {
|
||||
let _ = key;
|
||||
match self {
|
||||
Self::None => Ok(()),
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::MacOS => MacOSKeyStorage::new(SERVICE_NAME).delete_key(&key.pubkey),
|
||||
}
|
||||
}
|
||||
@@ -43,6 +49,7 @@ pub enum KeyStorageError {
|
||||
Retrieval,
|
||||
Addition(String),
|
||||
Removal(String),
|
||||
UnsupportedPlatform,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyStorageError {
|
||||
@@ -51,6 +58,10 @@ impl std::fmt::Display for KeyStorageError {
|
||||
Self::Retrieval => write!(f, "Failed to retrieve keys."),
|
||||
Self::Addition(key) => write!(f, "Failed to add key: {:?}", key),
|
||||
Self::Removal(key) => write!(f, "Failed to remove key: {:?}", key),
|
||||
Self::UnsupportedPlatform => write!(
|
||||
f,
|
||||
"Attempted to use a key storage impl from an unsupported platform."
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#![cfg(target_os = "macos")]
|
||||
|
||||
use enostr::{FullKeypair, Pubkey, SecretKey};
|
||||
|
||||
use security_framework::item::{ItemClass, ItemSearchOptions, Limit, SearchResult};
|
||||
use security_framework::passwords::{delete_generic_password, set_generic_password};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user