Skip to content

Commit

Permalink
KeyChainGroup: Be smarter about encryption order.
Browse files Browse the repository at this point in the history
This partly reverts commit 4ed5b0e3b06c18040d83be30df32e7be5b778b51.

(cherry picked from commit 5570b0b47639e4a1210ca317a69a0c49549404cc)
  • Loading branch information
matthewleon authored and HashEngineering committed Jun 25, 2024
1 parent 1818d67 commit 143da56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/org/bitcoinj/wallet/AnyKeyChainGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,17 @@ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
// This code must be exception safe.

AnyBasicKeyChain newBasic = basic.toEncrypted(keyCrypter, aesKey);
this.basic = newBasic;
List<AnyDeterministicKeyChain> newChains = new ArrayList<>();
if (chains != null) {
for (AnyDeterministicKeyChain chain : chains)
newChains.add(chain.toEncrypted(keyCrypter, aesKey));
}
this.keyCrypter = keyCrypter;
this.basic = newBasic;
if (chains != null) {
this.chains.clear();
this.chains.addAll(newChains);
}
this.keyCrypter = keyCrypter;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/bitcoinj/wallet/KeyChainGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,17 @@ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
// This code must be exception safe.

BasicKeyChain newBasic = basic.toEncrypted(keyCrypter, aesKey);
this.basic = newBasic;
List<DeterministicKeyChain> newChains = new ArrayList<>();
if (chains != null) {
for (DeterministicKeyChain chain : chains)
newChains.add(chain.toEncrypted(keyCrypter, aesKey));
}
this.keyCrypter = keyCrypter;
this.basic = newBasic;
if (chains != null) {
this.chains.clear();
this.chains.addAll(newChains);
}
this.keyCrypter = keyCrypter;
}

/**
Expand Down

0 comments on commit 143da56

Please sign in to comment.