Browse Source

CCrypter: move relevant implementation out of the header

0.16
Jonas Schnelli 7 years ago
parent
commit
208fda69b3
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 37
      src/wallet/crypter.cpp
  2. 44
      src/wallet/crypter.h

37
src/wallet/crypter.cpp

@ -153,6 +153,18 @@ bool CCryptoKeyStore::SetCrypted()
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()) if (!SetCrypted())
@ -239,6 +251,18 @@ bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<
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;
}
return false;
}
bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey& keyOut) const
{ {
{ {
@ -275,6 +299,19 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co
} }
} }
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)
{ {
{ {

44
src/wallet/crypter.h

@ -137,52 +137,16 @@ public:
{ {
} }
bool IsCrypted() const bool IsCrypted() const { return fUseCrypto; }
{ bool IsLocked() const;
return fUseCrypto;
}
bool IsLocked() const
{
if (!IsCrypted())
return false;
bool result;
{
LOCK(cs_KeyStore);
result = vMasterKey.empty();
}
return result;
}
bool Lock(); bool Lock();
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret); virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override; bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
bool HaveKey(const CKeyID &address) const override bool HaveKey(const CKeyID &address) const override;
{
{
LOCK(cs_KeyStore);
if (!IsCrypted()) {
return CBasicKeyStore::HaveKey(address);
}
return mapCryptedKeys.count(address) > 0;
}
return false;
}
bool GetKey(const CKeyID &address, CKey& keyOut) const override; bool GetKey(const CKeyID &address, CKey& keyOut) const override;
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override; bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
std::set<CKeyID> GetKeys() const override std::set<CKeyID> GetKeys() const override;
{
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;
}
/** /**
* Wallet status (encrypted, locked) changed. * Wallet status (encrypted, locked) changed.

Loading…
Cancel
Save