Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/crypter.cpp
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | |||||
bool CCryptoKeyStore::SetCrypted() { | bool CCryptoKeyStore::SetCrypted() { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
if (fUseCrypto) return true; | if (fUseCrypto) return true; | ||||
if (!mapKeys.empty()) return false; | if (!mapKeys.empty()) return false; | ||||
fUseCrypto = true; | fUseCrypto = true; | ||||
return true; | return true; | ||||
} | } | ||||
bool CCryptoKeyStore::IsLocked() const { | |||||
if (!IsCrypted()) { | |||||
return false; | |||||
} | |||||
bool result; | |||||
{ | |||||
LOCK(cs_KeyStore); | |||||
result = vMasterKey.empty(); | |||||
} | |||||
return result; | |||||
} | |||||
bool CCryptoKeyStore::Lock() { | bool CCryptoKeyStore::Lock() { | ||||
if (!SetCrypted()) return false; | if (!SetCrypted()) return false; | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
vMasterKey.clear(); | vMasterKey.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | const CPubKey &vchPubKey, const std::vector<uint8_t> &vchCryptedSecret) { | ||||
if (!SetCrypted()) return false; | if (!SetCrypted()) return false; | ||||
mapCryptedKeys[vchPubKey.GetID()] = | mapCryptedKeys[vchPubKey.GetID()] = | ||||
make_pair(vchPubKey, vchCryptedSecret); | make_pair(vchPubKey, vchCryptedSecret); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CCryptoKeyStore::HaveKey(const CKeyID &address) const { | |||||
LOCK(cs_KeyStore); | |||||
if (!IsCrypted()) { | |||||
return CBasicKeyStore::HaveKey(address); | |||||
} | |||||
return mapCryptedKeys.count(address) > 0; | |||||
} | |||||
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const { | bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const { | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
if (!IsCrypted()) return CBasicKeyStore::GetKey(address, keyOut); | if (!IsCrypted()) return CBasicKeyStore::GetKey(address, keyOut); | ||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address); | CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address); | ||||
if (mi != mapCryptedKeys.end()) { | if (mi != mapCryptedKeys.end()) { | ||||
const CPubKey &vchPubKey = (*mi).second.first; | const CPubKey &vchPubKey = (*mi).second.first; | ||||
Show All 17 Lines | bool CCryptoKeyStore::GetPubKey(const CKeyID &address, | ||||
return true; | return true; | ||||
} | } | ||||
// Check for watch-only pubkeys | // Check for watch-only pubkeys | ||||
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); | return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
std::set<CKeyID> CCryptoKeyStore::GetKeys() const { | |||||
LOCK(cs_KeyStore); | |||||
if (!IsCrypted()) { | |||||
return CBasicKeyStore::GetKeys(); | |||||
} | |||||
std::set<CKeyID> set_address; | |||||
for (const auto &mi : mapCryptedKeys) { | |||||
set_address.insert(mi.first); | |||||
} | |||||
return set_address; | |||||
} | |||||
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial &vMasterKeyIn) { | bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial &vMasterKeyIn) { | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
if (!mapCryptedKeys.empty() || IsCrypted()) return false; | if (!mapCryptedKeys.empty() || IsCrypted()) return false; | ||||
fUseCrypto = true; | fUseCrypto = true; | ||||
for (KeyMap::value_type &mKey : mapKeys) { | for (KeyMap::value_type &mKey : mapKeys) { | ||||
const CKey &key = mKey.second; | const CKey &key = mKey.second; | ||||
Show All 12 Lines |