Skip to content

Commit bda3a48

Browse files
committed
scripted-diff: wallet: rename plain and encrypted master key variables
-BEGIN VERIFY SCRIPT- sed -i s/_vMasterKey/plain_master_key/g ./src/wallet/wallet.cpp sed -i s/kMasterKey/master_key/g ./src/wallet/wallet.cpp sed -i "s/const MasterKeyMap::value_type& pMasterKey/const auto\& \[_, master_key\]/g" ./src/wallet/wallet.cpp sed -i s/pMasterKey\.second/master_key/g ./src/wallet/wallet.cpp sed -i "s/MasterKeyMap::value_type& pMasterKey/auto\& \[master_key_id, master_key\]/g" ./src/wallet/wallet.cpp sed -i s/pMasterKey\.first/master_key_id/g ./src/wallet/wallet.cpp -END VERIFY SCRIPT-
1 parent ba9f582 commit bda3a48

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/wallet/wallet.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -614,16 +614,16 @@ static bool DecryptMasterKey(const SecureString& wallet_passphrase, const CMaste
614614

615615
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
616616
{
617-
CKeyingMaterial _vMasterKey;
617+
CKeyingMaterial plain_master_key;
618618

619619
{
620620
LOCK(cs_wallet);
621-
for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
621+
for (const auto& [_, master_key] : mapMasterKeys)
622622
{
623-
if (!DecryptMasterKey(strWalletPassphrase, pMasterKey.second, _vMasterKey)) {
623+
if (!DecryptMasterKey(strWalletPassphrase, master_key, plain_master_key)) {
624624
continue; // try another master key
625625
}
626-
if (Unlock(_vMasterKey)) {
626+
if (Unlock(plain_master_key)) {
627627
// Now that we've unlocked, upgrade the key metadata
628628
UpgradeKeyMetadata();
629629
// Now that we've unlocked, upgrade the descriptor cache
@@ -643,20 +643,20 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
643643
LOCK2(m_relock_mutex, cs_wallet);
644644
Lock();
645645

646-
CKeyingMaterial _vMasterKey;
647-
for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
646+
CKeyingMaterial plain_master_key;
647+
for (auto& [master_key_id, master_key] : mapMasterKeys)
648648
{
649-
if (!DecryptMasterKey(strOldWalletPassphrase, pMasterKey.second, _vMasterKey)) {
649+
if (!DecryptMasterKey(strOldWalletPassphrase, master_key, plain_master_key)) {
650650
return false;
651651
}
652-
if (Unlock(_vMasterKey))
652+
if (Unlock(plain_master_key))
653653
{
654-
if (!EncryptMasterKey(strNewWalletPassphrase, _vMasterKey, pMasterKey.second)) {
654+
if (!EncryptMasterKey(strNewWalletPassphrase, plain_master_key, master_key)) {
655655
return false;
656656
}
657-
WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
657+
WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", master_key.nDeriveIterations);
658658

659-
WalletBatch(GetDatabase()).WriteMasterKey(pMasterKey.first, pMasterKey.second);
659+
WalletBatch(GetDatabase()).WriteMasterKey(master_key_id, master_key);
660660
if (fWasLocked)
661661
Lock();
662662
return true;
@@ -831,35 +831,35 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
831831
if (IsCrypted())
832832
return false;
833833

834-
CKeyingMaterial _vMasterKey;
834+
CKeyingMaterial plain_master_key;
835835

836-
_vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
837-
GetStrongRandBytes(_vMasterKey);
836+
plain_master_key.resize(WALLET_CRYPTO_KEY_SIZE);
837+
GetStrongRandBytes(plain_master_key);
838838

839-
CMasterKey kMasterKey;
839+
CMasterKey master_key;
840840

841-
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
842-
GetStrongRandBytes(kMasterKey.vchSalt);
841+
master_key.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
842+
GetStrongRandBytes(master_key.vchSalt);
843843

844-
if (!EncryptMasterKey(strWalletPassphrase, _vMasterKey, kMasterKey)) {
844+
if (!EncryptMasterKey(strWalletPassphrase, plain_master_key, master_key)) {
845845
return false;
846846
}
847-
WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
847+
WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", master_key.nDeriveIterations);
848848

849849
{
850850
LOCK2(m_relock_mutex, cs_wallet);
851-
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey;
851+
mapMasterKeys[++nMasterKeyMaxID] = master_key;
852852
WalletBatch* encrypted_batch = new WalletBatch(GetDatabase());
853853
if (!encrypted_batch->TxnBegin()) {
854854
delete encrypted_batch;
855855
encrypted_batch = nullptr;
856856
return false;
857857
}
858-
encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
858+
encrypted_batch->WriteMasterKey(nMasterKeyMaxID, master_key);
859859

860860
for (const auto& spk_man_pair : m_spk_managers) {
861861
auto spk_man = spk_man_pair.second.get();
862-
if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) {
862+
if (!spk_man->Encrypt(plain_master_key, encrypted_batch)) {
863863
encrypted_batch->TxnAbort();
864864
delete encrypted_batch;
865865
encrypted_batch = nullptr;

0 commit comments

Comments
 (0)