MCPcopy Create free account
hub / github.com/ElementsProject/elements / CheckDecryptionKey

Method CheckDecryptionKey

src/wallet/scriptpubkeyman.cpp:236–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236bool LegacyScriptPubKeyMan::CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys)
237{
238 {
239 LOCK(cs_KeyStore);
240 assert(mapKeys.empty());
241
242 bool keyPass = mapCryptedKeys.empty(); // Always pass when there are no encrypted keys
243 bool keyFail = false;
244 CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
245 WalletBatch batch(m_storage.GetDatabase());
246 for (; mi != mapCryptedKeys.end(); ++mi)
247 {
248 const CPubKey &vchPubKey = (*mi).second.first;
249 const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
250 CKey key;
251 if (!DecryptKey(master_key, vchCryptedSecret, vchPubKey, key))
252 {
253 keyFail = true;
254 break;
255 }
256 keyPass = true;
257 if (fDecryptionThoroughlyChecked)
258 break;
259 else {
260 // Rewrite these encrypted keys with checksums
261 batch.WriteCryptedKey(vchPubKey, vchCryptedSecret, mapKeyMetadata[vchPubKey.GetID()]);
262 }
263 }
264 if (keyPass && keyFail)
265 {
266 LogPrintf("The wallet is probably corrupted: Some keys decrypt but not all.\n");
267 throw std::runtime_error("Error unlocking wallet: some keys decrypt but not all. Your wallet file may be corrupt.");
268 }
269 if (keyFail || (!keyPass && !accept_no_keys))
270 return false;
271 fDecryptionThoroughlyChecked = true;
272 }
273 return true;
274}
275
276bool LegacyScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch)
277{

Callers 2

UnlockMethod · 0.45

Calls 6

DecryptKeyFunction · 0.85
WriteCryptedKeyMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetIDMethod · 0.45

Tested by

no test coverage detected