Skip to content

Commit

Permalink
CCrypter: move relevant implementation out of the header
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Oct 5, 2017
1 parent 3155fd2 commit 208fda6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
37 changes: 37 additions & 0 deletions src/wallet/crypter.cpp
Expand Up @@ -153,6 +153,18 @@ bool CCryptoKeyStore::SetCrypted()
return true;
}

bool CCryptoKeyStore::IsLocked() const
{
if (!IsCrypted())
return false;
bool result;
{
LOCK(cs_KeyStore);
result = vMasterKey.empty();
}
return result;
}

bool CCryptoKeyStore::Lock()
{
if (!SetCrypted())
Expand Down Expand Up @@ -239,6 +251,18 @@ bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<
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
{
{
Expand Down Expand Up @@ -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)
{
{
Expand Down
44 changes: 4 additions & 40 deletions src/wallet/crypter.h
Expand Up @@ -137,52 +137,16 @@ class CCryptoKeyStore : public CBasicKeyStore
{
}

bool IsCrypted() const
{
return fUseCrypto;
}

bool IsLocked() const
{
if (!IsCrypted())
return false;
bool result;
{
LOCK(cs_KeyStore);
result = vMasterKey.empty();
}
return result;
}

bool IsCrypted() const { return fUseCrypto; }
bool IsLocked() const;
bool Lock();

virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) 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 HaveKey(const CKeyID &address) const override;
bool GetKey(const CKeyID &address, CKey& keyOut) const override;
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) 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;
}
std::set<CKeyID> GetKeys() const override;

/**
* Wallet status (encrypted, locked) changed.
Expand Down

0 comments on commit 208fda6

Please sign in to comment.