Skip to content

Commit cbf2324

Browse files
committed
Add platforms
1 parent 2949c6e commit cbf2324

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ async-trait = { version = "0.1.89", optional = true }
1919
async-fs = { version = "2.2.0", optional = true }
2020
tokio = { version = "1.51.0", features = ["fs"], optional = true }
2121

22-
[target.'cfg(target_os = "linux")'.dependencies]
22+
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
2323
keyring = { version = "3.6.3", features = ["linux-native"] }
2424

25-
[target.'cfg(target_os = "macos")'.dependencies]
25+
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
2626
keyring = { version = "3.6.3", features = ["apple-native"] }
2727

2828
[target.'cfg(target_os = "windows")'.dependencies]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
- **Secure** - Secure your data using the XChaCha20Poly1305 algorithm without the hassle of storing and retrieving encryption keys manually.
1010

1111
## Supported Platforms
12-
- [x] Desktop: Windows, MacOS, Linux.
13-
- [ ] Mobile: iOS, Android.
12+
- [x] Desktop: Windows, MacOS, Linux, FreeBSD, OpenBSD.
13+
- [x] Mobile: iOS (Android work-in-progress).
1414
- [ ] Web
1515

1616
## Getting Started 🚀

build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ fn main() {
66
}
77

88
cfg_aliases::cfg_aliases! {
9-
use_keyring: { any(target_os = "linux", target_os = "macos", target_os = "windows") },
9+
use_keyring: {
10+
any(
11+
target_os = "linux",
12+
target_os = "macos",
13+
target_os = "ios",
14+
target_os = "windows",
15+
target_os = "freebsd",
16+
target_os = "openbsd"
17+
)
18+
},
1019
async_api: { any(feature = "tokio", feature = "async-fs") }
1120
}
1221
}

src/secure/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ const NONCE_SIZE: usize = 24;
2323
pub static KEY_STORE: OnceLock<Box<dyn KeyStore>> = OnceLock::new();
2424

2525
/// Returns the set [KeyStore] implementation, initializing it with the default if necessary.
26-
pub fn get_key_store<'a>() -> &'a Box<dyn KeyStore> {
26+
pub fn get_key_store<'a>() -> &'a dyn KeyStore {
2727
KEY_STORE.get_or_init(default_key_store)
2828
}
2929

3030
/// Returns the default [KeyStore] implementation for this platform.
3131
pub fn default_key_store() -> Box<dyn KeyStore> {
3232
#[cfg(use_keyring)]
3333
{
34-
return Box::new(keyring::KeyStore);
34+
Box::new(keyring::KeyStore)
3535
}
36+
3637
#[cfg(not(use_keyring))]
3738
{
3839
panic!("Platform not supported!");
@@ -108,3 +109,13 @@ pub trait KeyStore: Send + Sync + 'static {
108109
/// Sets the key with the given name.
109110
fn set_key(&self, name: &str, key: Vec<u8>) -> Result<(), Error>;
110111
}
112+
113+
impl KeyStore for Box<dyn KeyStore> {
114+
fn get_key(&self, name: &str) -> Result<Option<Vec<u8>>, Error> {
115+
(**self).get_key(name)
116+
}
117+
118+
fn set_key(&self, name: &str, key: Vec<u8>) -> Result<(), Error> {
119+
(**self).set_key(name, key)
120+
}
121+
}

0 commit comments

Comments
 (0)