Skip to content

Commit

Permalink
adjust code after third review
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Oct 15, 2024
1 parent 3b22966 commit 827fd6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ exclude = [".github/"]
readme = "README.md"

[features]
linux-native = ["keyutils"]
linux-native = ["dep:linux-keyutils"]
apple-native = ["dep:security-framework"]
windows-native = ["dep:windows-sys", "dep:byteorder"]

keyutils = ["dep:linux-keyutils"]
sync-persistent-keyutils = ["keyutils", "sync-secret-service"]
async-persistent-keyutils = ["keyutils", "async-secret-service"]
sync-persistent-keyutils = ["dep:linux-keyutils", "sync-secret-service"]
async-persistent-keyutils = ["dep:linux-keyutils", "async-secret-service"]
sync-secret-service = ["dep:dbus-secret-service"]
async-secret-service = ["dep:secret-service", "dep:zbus"]
crypto-rust = ["dbus-secret-service?/crypto-rust", "secret-service?/crypto-rust"]
Expand Down
29 changes: 6 additions & 23 deletions src/keyutils_persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
TODO
*/
use std::collections::HashMap;

use crate::credential::{
use super::credential::{
Credential, CredentialApi, CredentialBuilder, CredentialBuilderApi, CredentialPersistence,
};
use crate::keyutils::KeyutilsCredential;
use crate::secret_service::SsCredential;
use crate::{Error, Result};
use super::error::{Error, Result};
use super::keyutils::KeyutilsCredential;
use super::secret_service::SsCredential;

#[derive(Debug, Clone)]
pub struct KeyutilsPersistentCredential {
Expand Down Expand Up @@ -59,24 +57,9 @@ impl CredentialApi for KeyutilsPersistentCredential {
Ok(secret)
}

fn get_attributes(&self) -> Result<HashMap<String, String>> {
let Ok(attributes) = self.ss.get_attributes() else {
return self.keyutils.get_attributes();
};

Ok(attributes)
}

fn update_attributes(&self, attributes: &HashMap<&str, &str>) -> Result<()> {
let Ok(()) = self.ss.update_attributes(attributes) else {
return self.keyutils.update_attributes(attributes);
};

Ok(())
}

fn delete_credential(&self) -> Result<()> {
self.keyutils.delete_credential()?;
// TODO: log the error
let _ = self.keyutils.delete_credential();
self.ss.delete_credential()?;
Ok(())
}
Expand Down
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,19 @@ pub mod mock;
feature = "async-persistent-keyutils",
)
))]
compile_error!("This crate cannot use the secret-service both synchronously and asynchronously");
compile_error!("This crate cannot use both the sync and async versions of any credential store");

//
// pick the *nix keystore
//
#[cfg(all(target_os = "linux", feature = "keyutils"))]
#[cfg(all(
target_os = "linux",
any(
feature = "linux-native",
feature = "sync-persistent-keyutils",
feature = "async-persistent-keyutils",
)
))]
pub mod keyutils;
#[cfg(all(
target_os = "linux",
Expand Down Expand Up @@ -239,11 +246,9 @@ pub use keyutils_persistent as default;
// fallback to mock if neither keyutils nor secret service is available
#[cfg(all(
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
not(any(
feature = "keyutils",
feature = "sync-secret-service",
feature = "async-secret-service",
)),
not(feature = "linux-native"),
not(feature = "sync-secret-service"),
not(feature = "async-secret-service"),
))]
pub use mock as default;

Expand Down

0 comments on commit 827fd6e

Please sign in to comment.