Skip to content

Commit

Permalink
adjust code after forth review
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Oct 15, 2024
1 parent b41fafc commit d09aff3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/keyutils_persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ impl CredentialApi for KeyutilsPersistentCredential {
}

fn get_password(&self) -> Result<String> {
if let Ok(password) = self.keyutils.get_password() {
return Ok(password);
match self.keyutils.get_password() {
Ok(password) => {
return Ok(password);
}
Err(err) => {
debug!("cannot get password from keyutils: {err}, trying from secret service")
}
}

let password = self.ss.get_password().map_err(ambigous_to_no_entry)?;
Expand All @@ -49,8 +54,13 @@ impl CredentialApi for KeyutilsPersistentCredential {
}

fn get_secret(&self) -> Result<Vec<u8>> {
if let Ok(secret) = self.keyutils.get_secret() {
return Ok(secret);
match self.keyutils.get_secret() {
Ok(secret) => {
return Ok(secret);
}
Err(err) => {
debug!("cannot get secret from keyutils: {err}, trying from secret service")
}
}

let secret = self.ss.get_secret().map_err(ambigous_to_no_entry)?;
Expand All @@ -63,6 +73,7 @@ impl CredentialApi for KeyutilsPersistentCredential {
if let Err(err) = self.keyutils.delete_credential() {
debug!("cannot delete keyutils credential: {err}");
}

self.ss.delete_credential()
}

Expand Down
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,18 @@ pub mod keyutils_persistent;
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(feature = "linux-native"),
not(feature = "sync-secret-service"),
not(feature = "async-secret-service"),
#[cfg(any(
all(
target_os = "linux",
not(feature = "linux-native"),
not(feature = "sync-secret-service"),
not(feature = "async-secret-service"),
),
all(
any(target_os = "freebsd", target_os = "openbsd"),
not(feature = "sync-secret-service"),
not(feature = "async-secret-service"),
)
))]
pub use mock as default;

Expand Down

0 comments on commit d09aff3

Please sign in to comment.