This commit is contained in:
Sebastian Stenzel
2020-05-26 09:21:18 +02:00
parent f72035210c
commit c13449c6ad
3 changed files with 10 additions and 5 deletions
@@ -29,7 +29,7 @@ interface KeychainAccessStrategy {
void deletePassphrase(String key) throws KeychainAccessException;
/**
* Updates a passphrase with a given key.
* Updates a passphrase with a given key. Noop, if there is no item for the given key.
*
* @param key Unique key previously used while {@link #storePassphrase(String, CharSequence) storing a passphrase}.
* @param passphrase The secret to be updated in this keychain.
@@ -49,8 +49,10 @@ class MacSystemKeychainAccess implements KeychainAccessStrategy {
}
@Override
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
storePassphrase(key, passphrase);
public void changePassphrase(String key, CharSequence passphrase) {
if (keychain().deletePassword(key)) {
keychain().storePassword(key, passphrase);
}
}
}
@@ -115,8 +115,11 @@ class WindowsProtectedKeychainAccess implements KeychainAccessStrategy {
}
@Override
public void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
storePassphrase(key, passphrase);
public void changePassphrase(String key, CharSequence passphrase) {
loadKeychainEntriesIfNeeded();
if (keychainEntries.remove(key) != null) {
storePassphrase(key, passphrase);
}
}
@Override