From 028e820f7129daa0e08d1bf08790b3e037539f53 Mon Sep 17 00:00:00 2001 From: muji Date: Sat, 13 Jul 2024 09:15:42 +0800 Subject: [PATCH 1/5] Add set_secret() and get_secret() for iOS impl. --- src/ios.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ios.rs b/src/ios.rs index d8c9486..dade6fa 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -47,6 +47,16 @@ impl CredentialApi for IosCredential { Ok(()) } + /// Create and write a credential with secret for this entry. + /// + /// The new credential replaces any existing one in the store. + /// Since there is only one credential with a given _account_ and _user_ + /// in any given keychain, there is no chance of ambiguity. + fn set_secret(&self, secret: &[u8]) -> Result<()> { + set_generic_password(&self.service, &self.account, secret).map_err(decode_error)?; + Ok(()) + } + /// Look up the password for this entry, if any. /// /// Returns a [NoEntry](ErrorCode::NoEntry) error if there is no @@ -57,6 +67,14 @@ impl CredentialApi for IosCredential { decode_password(password_bytes.to_vec()) } + /// Look up the secret for this entry, if any. + /// + /// Returns a [NoEntry](ErrorCode::NoEntry) error if there is no + /// credential in the store. + fn get_secret(&self) -> Result> { + get_generic_password(&self.service, &self.account).map_err(decode_error) + } + /// Delete the underlying generic credential for this entry, if any. /// /// Returns a [NoEntry](ErrorCode::NoEntry) error if there is no From 1af5fd66ab335e27b39c8b227e8a0c3ae270cbce Mon Sep 17 00:00:00 2001 From: muji Date: Sat, 13 Jul 2024 09:45:27 +0800 Subject: [PATCH 2/5] Call secret functions from passwords functions on iOS. --- src/ios.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ios.rs b/src/ios.rs index dade6fa..196392e 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -42,8 +42,7 @@ impl CredentialApi for IosCredential { /// Since there is only one credential with a given _account_ and _user_ /// in any given keychain, there is no chance of ambiguity. fn set_password(&self, password: &str) -> Result<()> { - set_generic_password(&self.service, &self.account, password.as_bytes()) - .map_err(decode_error)?; + self.set_secret(password.as_bytes())?; Ok(()) } @@ -62,8 +61,7 @@ impl CredentialApi for IosCredential { /// Returns a [NoEntry](ErrorCode::NoEntry) error if there is no /// credential in the store. fn get_password(&self) -> Result { - let password_bytes = - get_generic_password(&self.service, &self.account).map_err(decode_error)?; + let password_bytes = self.get_secret()?; decode_password(password_bytes.to_vec()) } From cf612130e2b86f4b7513a5036cf79af3792669ea Mon Sep 17 00:00:00 2001 From: muji Date: Sat, 13 Jul 2024 09:51:30 +0800 Subject: [PATCH 3/5] Update README. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index af2bf2c..e933cf6 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ Thanks to the following for helping make this library better, whether through co - @steveatinfincia - @Sytten - @thewh1teagle +- @tmpfs - @VorpalBlade - @zschreur From 8c67a58de24290f965974a6785748ffb7de46a2a Mon Sep 17 00:00:00 2001 From: muji Date: Sat, 13 Jul 2024 10:07:25 +0800 Subject: [PATCH 4/5] Fix redundant call to to_vec(). --- src/ios.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios.rs b/src/ios.rs index 196392e..32430fe 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -62,7 +62,7 @@ impl CredentialApi for IosCredential { /// credential in the store. fn get_password(&self) -> Result { let password_bytes = self.get_secret()?; - decode_password(password_bytes.to_vec()) + decode_password(password_bytes) } /// Look up the secret for this entry, if any. From 060b6c462b126ae939e188f4930cb4b315a9a574 Mon Sep 17 00:00:00 2001 From: muji Date: Sat, 13 Jul 2024 10:07:56 +0800 Subject: [PATCH 5/5] Update use statement. --- examples/ios.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ios.rs b/examples/ios.rs index 3f76be0..06e3e1f 100644 --- a/examples/ios.rs +++ b/examples/ios.rs @@ -89,7 +89,7 @@ fn test_update_password() { #[cfg(target_os = "ios")] fn test_get_credential() { - use keyring::default::IosCredential; + use keyring::ios::IosCredential; let name = "test_get_credential".to_string(); let entry = Entry::new(&name, &name).expect("Can't create entry"); let credential: &IosCredential = entry