mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Fix code style in keystore.cpp/crypter.cpp
This commit is contained in:
parent
208fda69b3
commit
dd9bb253c3
@ -54,14 +54,11 @@ std::set<CKeyID> CBasicKeyStore::GetKeys() const
|
|||||||
|
|
||||||
bool CBasicKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const
|
bool CBasicKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
KeyMap::const_iterator mi = mapKeys.find(address);
|
||||||
KeyMap::const_iterator mi = mapKeys.find(address);
|
if (mi != mapKeys.end()) {
|
||||||
if (mi != mapKeys.end())
|
keyOut = mi->second;
|
||||||
{
|
return true;
|
||||||
keyOut = mi->second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -155,14 +155,11 @@ bool CCryptoKeyStore::SetCrypted()
|
|||||||
|
|
||||||
bool CCryptoKeyStore::IsLocked() const
|
bool CCryptoKeyStore::IsLocked() const
|
||||||
{
|
{
|
||||||
if (!IsCrypted())
|
if (!IsCrypted()) {
|
||||||
return false;
|
return false;
|
||||||
bool result;
|
|
||||||
{
|
|
||||||
LOCK(cs_KeyStore);
|
|
||||||
result = vMasterKey.empty();
|
|
||||||
}
|
}
|
||||||
return result;
|
LOCK(cs_KeyStore);
|
||||||
|
return vMasterKey.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCryptoKeyStore::Lock()
|
bool CCryptoKeyStore::Lock()
|
||||||
@ -219,21 +216,23 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
|
|||||||
|
|
||||||
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
if (!IsCrypted()) {
|
||||||
if (!IsCrypted())
|
return CBasicKeyStore::AddKeyPubKey(key, pubkey);
|
||||||
return CBasicKeyStore::AddKeyPubKey(key, pubkey);
|
}
|
||||||
|
|
||||||
if (IsLocked())
|
if (IsLocked()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> vchCryptedSecret;
|
std::vector<unsigned char> vchCryptedSecret;
|
||||||
CKeyingMaterial vchSecret(key.begin(), key.end());
|
CKeyingMaterial vchSecret(key.begin(), key.end());
|
||||||
if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret))
|
if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!AddCryptedKey(pubkey, vchCryptedSecret))
|
if (!AddCryptedKey(pubkey, vchCryptedSecret)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -241,62 +240,55 @@ bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
|||||||
|
|
||||||
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
if (!SetCrypted()) {
|
||||||
if (!SetCrypted())
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCryptoKeyStore::HaveKey(const CKeyID &address) const
|
bool CCryptoKeyStore::HaveKey(const CKeyID &address) const
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
if (!IsCrypted()) {
|
||||||
if (!IsCrypted()) {
|
return CBasicKeyStore::HaveKey(address);
|
||||||
return CBasicKeyStore::HaveKey(address);
|
|
||||||
}
|
|
||||||
return mapCryptedKeys.count(address) > 0;
|
|
||||||
}
|
}
|
||||||
return false;
|
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()) {
|
||||||
if (!IsCrypted())
|
return CBasicKeyStore::GetKey(address, keyOut);
|
||||||
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;
|
||||||
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
|
const std::vector<unsigned char> &vchCryptedSecret = (*mi).second.second;
|
||||||
return DecryptKey(vMasterKey, vchCryptedSecret, vchPubKey, keyOut);
|
return DecryptKey(vMasterKey, vchCryptedSecret, vchPubKey, keyOut);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
|
bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
if (!IsCrypted())
|
||||||
if (!IsCrypted())
|
|
||||||
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
|
|
||||||
|
|
||||||
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
|
|
||||||
if (mi != mapCryptedKeys.end())
|
|
||||||
{
|
|
||||||
vchPubKeyOut = (*mi).second.first;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Check for watch-only pubkeys
|
|
||||||
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
|
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
|
||||||
|
|
||||||
|
CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address);
|
||||||
|
if (mi != mapCryptedKeys.end())
|
||||||
|
{
|
||||||
|
vchPubKeyOut = (*mi).second.first;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
// Check for watch-only pubkeys
|
||||||
|
return CBasicKeyStore::GetPubKey(address, vchPubKeyOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<CKeyID> CCryptoKeyStore::GetKeys() const
|
std::set<CKeyID> CCryptoKeyStore::GetKeys() const
|
||||||
@ -314,24 +306,22 @@ std::set<CKeyID> CCryptoKeyStore::GetKeys() const
|
|||||||
|
|
||||||
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
|
||||||
{
|
{
|
||||||
{
|
LOCK(cs_KeyStore);
|
||||||
LOCK(cs_KeyStore);
|
if (!mapCryptedKeys.empty() || IsCrypted())
|
||||||
if (!mapCryptedKeys.empty() || IsCrypted())
|
return false;
|
||||||
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;
|
||||||
CPubKey vchPubKey = key.GetPubKey();
|
CPubKey vchPubKey = key.GetPubKey();
|
||||||
CKeyingMaterial vchSecret(key.begin(), key.end());
|
CKeyingMaterial vchSecret(key.begin(), key.end());
|
||||||
std::vector<unsigned char> vchCryptedSecret;
|
std::vector<unsigned char> vchCryptedSecret;
|
||||||
if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
|
if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret))
|
||||||
return false;
|
return false;
|
||||||
if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
|
if (!AddCryptedKey(vchPubKey, vchCryptedSecret))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
mapKeys.clear();
|
|
||||||
}
|
}
|
||||||
|
mapKeys.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user