From a8333fc9ff9adaa97a1f9024f5783cc071777150 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sun, 1 Dec 2024 04:33:25 +0100 Subject: [PATCH] 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- --- src/wallet/wallet.cpp | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index cf01b49951e..7c409eb4bc8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -620,16 +620,16 @@ static bool DecryptMasterKey(const SecureString& wallet_passphrase, const CMaste bool CWallet::Unlock(const SecureString& strWalletPassphrase) { - CKeyingMaterial _vMasterKey; + CKeyingMaterial plain_master_key; { LOCK(cs_wallet); - for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys) + for (const auto& [_, master_key] : mapMasterKeys) { - if (!DecryptMasterKey(strWalletPassphrase, pMasterKey.second, _vMasterKey)) { + if (!DecryptMasterKey(strWalletPassphrase, master_key, plain_master_key)) { continue; // try another master key } - if (Unlock(_vMasterKey)) { + if (Unlock(plain_master_key)) { // Now that we've unlocked, upgrade the key metadata UpgradeKeyMetadata(); // Now that we've unlocked, upgrade the descriptor cache @@ -649,20 +649,20 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, LOCK2(m_relock_mutex, cs_wallet); Lock(); - CKeyingMaterial _vMasterKey; - for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys) + CKeyingMaterial plain_master_key; + for (auto& [master_key_id, master_key] : mapMasterKeys) { - if (!DecryptMasterKey(strOldWalletPassphrase, pMasterKey.second, _vMasterKey)) { + if (!DecryptMasterKey(strOldWalletPassphrase, master_key, plain_master_key)) { return false; } - if (Unlock(_vMasterKey)) + if (Unlock(plain_master_key)) { - if (!EncryptMasterKey(strNewWalletPassphrase, _vMasterKey, pMasterKey.second)) { + if (!EncryptMasterKey(strNewWalletPassphrase, plain_master_key, master_key)) { return false; } - WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations); + WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", master_key.nDeriveIterations); - WalletBatch(GetDatabase()).WriteMasterKey(pMasterKey.first, pMasterKey.second); + WalletBatch(GetDatabase()).WriteMasterKey(master_key_id, master_key); if (fWasLocked) Lock(); return true; @@ -837,35 +837,35 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) if (IsCrypted()) return false; - CKeyingMaterial _vMasterKey; + CKeyingMaterial plain_master_key; - _vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); - GetStrongRandBytes(_vMasterKey); + plain_master_key.resize(WALLET_CRYPTO_KEY_SIZE); + GetStrongRandBytes(plain_master_key); - CMasterKey kMasterKey; + CMasterKey master_key; - kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); - GetStrongRandBytes(kMasterKey.vchSalt); + master_key.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); + GetStrongRandBytes(master_key.vchSalt); - if (!EncryptMasterKey(strWalletPassphrase, _vMasterKey, kMasterKey)) { + if (!EncryptMasterKey(strWalletPassphrase, plain_master_key, master_key)) { return false; } - WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations); + WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", master_key.nDeriveIterations); { LOCK2(m_relock_mutex, cs_wallet); - mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; + mapMasterKeys[++nMasterKeyMaxID] = master_key; WalletBatch* encrypted_batch = new WalletBatch(GetDatabase()); if (!encrypted_batch->TxnBegin()) { delete encrypted_batch; encrypted_batch = nullptr; return false; } - encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey); + encrypted_batch->WriteMasterKey(nMasterKeyMaxID, master_key); for (const auto& spk_man_pair : m_spk_managers) { auto spk_man = spk_man_pair.second.get(); - if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) { + if (!spk_man->Encrypt(plain_master_key, encrypted_batch)) { encrypted_batch->TxnAbort(); delete encrypted_batch; encrypted_batch = nullptr;