diff --git a/Cargo.toml b/Cargo.toml index f3a513d..0979970 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/key_storage.rs b/src/key_storage.rs index 795aa62..06d1814 100644 --- a/src/key_storage.rs +++ b/src/key_storage.rs @@ -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, 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." + ), } } } diff --git a/src/macos_key_storage.rs b/src/macos_key_storage.rs index 387ff87..9e63b8c 100644 --- a/src/macos_key_storage.rs +++ b/src/macos_key_storage.rs @@ -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};