mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Factor out two small duplcated code blocks
This commit is contained in:
parent
9b156b86dd
commit
fbb025adb1
1 changed files with 19 additions and 12 deletions
|
@ -51,9 +51,7 @@ class CoreWalletService {
|
||||||
if (!walletsManager.areWalletsAvailable())
|
if (!walletsManager.areWalletsAvailable())
|
||||||
throw new IllegalStateException("wallet is not yet available");
|
throw new IllegalStateException("wallet is not yet available");
|
||||||
|
|
||||||
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();
|
||||||
if (keyCrypterScrypt == null)
|
|
||||||
throw new IllegalStateException("wallet encrypter is not available");
|
|
||||||
|
|
||||||
if (newPassword != null && !newPassword.isEmpty()) {
|
if (newPassword != null && !newPassword.isEmpty()) {
|
||||||
// TODO Validate new password before replacing old password.
|
// TODO Validate new password before replacing old password.
|
||||||
|
@ -108,15 +106,8 @@ class CoreWalletService {
|
||||||
// Provided for automated wallet protection method testing, despite the
|
// Provided for automated wallet protection method testing, despite the
|
||||||
// security risks exposed by providing users the ability to decrypt their wallets.
|
// security risks exposed by providing users the ability to decrypt their wallets.
|
||||||
public void removeWalletPassword(String password) {
|
public void removeWalletPassword(String password) {
|
||||||
if (!walletsManager.areWalletsAvailable())
|
verifyWalletIsAvailableAndEncrypted();
|
||||||
throw new IllegalStateException("wallet is not yet available");
|
KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();
|
||||||
|
|
||||||
if (!walletsManager.areWalletsEncrypted())
|
|
||||||
throw new IllegalStateException("wallet is not encrypted with a password");
|
|
||||||
|
|
||||||
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
|
||||||
if (keyCrypterScrypt == null)
|
|
||||||
throw new IllegalStateException("wallet encrypter is not available");
|
|
||||||
|
|
||||||
KeyParameter aesKey = keyCrypterScrypt.deriveKey(password);
|
KeyParameter aesKey = keyCrypterScrypt.deriveKey(password);
|
||||||
if (!walletsManager.checkAESKey(aesKey))
|
if (!walletsManager.checkAESKey(aesKey))
|
||||||
|
@ -124,4 +115,20 @@ class CoreWalletService {
|
||||||
|
|
||||||
walletsManager.decryptWallets(aesKey);
|
walletsManager.decryptWallets(aesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throws a RuntimeException if wallets are not available or not encrypted.
|
||||||
|
private void verifyWalletIsAvailableAndEncrypted() {
|
||||||
|
if (!walletsManager.areWalletsAvailable())
|
||||||
|
throw new IllegalStateException("wallet is not yet available");
|
||||||
|
|
||||||
|
if (!walletsManager.areWalletsEncrypted())
|
||||||
|
throw new IllegalStateException("wallet is not encrypted with a password");
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyCrypterScrypt getKeyCrypterScrypt() {
|
||||||
|
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
||||||
|
if (keyCrypterScrypt == null)
|
||||||
|
throw new IllegalStateException("wallet encrypter is not available");
|
||||||
|
return keyCrypterScrypt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue