mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 06:55:08 +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())
|
||||
throw new IllegalStateException("wallet is not yet available");
|
||||
|
||||
KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
|
||||
if (keyCrypterScrypt == null)
|
||||
throw new IllegalStateException("wallet encrypter is not available");
|
||||
KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();
|
||||
|
||||
if (newPassword != null && !newPassword.isEmpty()) {
|
||||
// TODO Validate new password before replacing old password.
|
||||
|
@ -108,15 +106,8 @@ class CoreWalletService {
|
|||
// Provided for automated wallet protection method testing, despite the
|
||||
// security risks exposed by providing users the ability to decrypt their wallets.
|
||||
public void removeWalletPassword(String password) {
|
||||
if (!walletsManager.areWalletsAvailable())
|
||||
throw new IllegalStateException("wallet is not yet available");
|
||||
|
||||
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");
|
||||
verifyWalletIsAvailableAndEncrypted();
|
||||
KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();
|
||||
|
||||
KeyParameter aesKey = keyCrypterScrypt.deriveKey(password);
|
||||
if (!walletsManager.checkAESKey(aesKey))
|
||||
|
@ -124,4 +115,20 @@ class CoreWalletService {
|
|||
|
||||
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