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 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 diff --git a/src/ios.rs b/src/ios.rs index d8c9486..32430fe 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -42,8 +42,17 @@ 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(()) + } + + /// 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(()) } @@ -52,9 +61,16 @@ 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)?; - decode_password(password_bytes.to_vec()) + let password_bytes = self.get_secret()?; + decode_password(password_bytes) + } + + /// 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.