| 353 | } |
| 354 | |
| 355 | bool LoadCryptedKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr) |
| 356 | { |
| 357 | LOCK(pwallet->cs_wallet); |
| 358 | try { |
| 359 | CPubKey vchPubKey; |
| 360 | ssKey >> vchPubKey; |
| 361 | if (!vchPubKey.IsValid()) |
| 362 | { |
| 363 | strErr = "Error reading wallet database: CPubKey corrupt"; |
| 364 | return false; |
| 365 | } |
| 366 | std::vector<unsigned char> vchPrivKey; |
| 367 | ssValue >> vchPrivKey; |
| 368 | |
| 369 | // Get the checksum and check it |
| 370 | bool checksum_valid = false; |
| 371 | if (!ssValue.empty()) { |
| 372 | uint256 checksum; |
| 373 | ssValue >> checksum; |
| 374 | if (!(checksum_valid = Hash(vchPrivKey) == checksum)) { |
| 375 | strErr = "Error reading wallet database: Encrypted key corrupt"; |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | if (!pwallet->GetOrCreateLegacyDataSPKM()->LoadCryptedKey(vchPubKey, vchPrivKey, checksum_valid)) |
| 381 | { |
| 382 | strErr = "Error reading wallet database: LegacyDataSPKM::LoadCryptedKey failed"; |
| 383 | return false; |
| 384 | } |
| 385 | } catch (const std::exception& e) { |
| 386 | if (strErr.empty()) { |
| 387 | strErr = e.what(); |
| 388 | } |
| 389 | return false; |
| 390 | } |
| 391 | return true; |
| 392 | } |
| 393 | |
| 394 | bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue, std::string& strErr) |
| 395 | { |
no test coverage detected