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 28ddd04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/keyutils_persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ 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, trying from secret service"),

Check failure on line 43 in src/keyutils_persistent.rs

View workflow job for this annotation

GitHub Actions / ci_nix (linux-native-sync-persistent,crypto-rust)

unused variable: `err`

Check failure on line 43 in src/keyutils_persistent.rs

View workflow job for this annotation

GitHub Actions / ci_nix (linux-native-sync-persistent,crypto-openssl)

unused variable: `err`
}

let password = self.ss.get_password().map_err(ambigous_to_no_entry)?;
Expand All @@ -49,8 +50,9 @@ 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, trying from secret service"),

Check failure on line 55 in src/keyutils_persistent.rs

View workflow job for this annotation

GitHub Actions / ci_nix (linux-native-sync-persistent,crypto-rust)

unused variable: `err`

Check failure on line 55 in src/keyutils_persistent.rs

View workflow job for this annotation

GitHub Actions / ci_nix (linux-native-sync-persistent,crypto-openssl)

unused variable: `err`
}

let secret = self.ss.get_secret().map_err(ambigous_to_no_entry)?;
Expand All @@ -63,6 +65,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 28ddd04

Please sign in to comment.