diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-09-02 17:35:30 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-09-02 17:35:30 +0200 |
commit | 7a15d4ff67c9a6e3b6b5a63f82f76ffe1937c3b8 (patch) | |
tree | 8ac8a0e7b9994ade96f635dd261c5ae46703f7df /src/keystore.h | |
parent | f43f46c175d7e6d7426536f8efcad05d2eafba80 (diff) | |
parent | 86fd7c5af6cf3f907c50cf25ff844cd23e271c70 (diff) | |
download | bitcoin-7a15d4ff67c9a6e3b6b5a63f82f76ffe1937c3b8.tar.xz |
Merge branch 'master' of https://github.com/bitcoin/bitcoin
Conflicts:
src/main.cpp
Diffstat (limited to 'src/keystore.h')
-rw-r--r-- | src/keystore.h | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/keystore.h b/src/keystore.h index 0324cc6e1b..bbfac83d1f 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -9,9 +9,10 @@ class CKeyStore { -public: +protected: mutable CCriticalSection cs_KeyStore; +public: virtual bool AddKey(const CKey& key) =0; virtual bool HaveKey(const CBitcoinAddress &address) const =0; virtual bool GetKey(const CBitcoinAddress &address, CKey& keyOut) const =0; @@ -30,15 +31,21 @@ public: bool AddKey(const CKey& key); bool HaveKey(const CBitcoinAddress &address) const { - return (mapKeys.count(address) > 0); + bool result; + CRITICAL_BLOCK(cs_KeyStore) + result = (mapKeys.count(address) > 0); + return result; } bool GetKey(const CBitcoinAddress &address, CKey& keyOut) const { - KeyMap::const_iterator mi = mapKeys.find(address); - if (mi != mapKeys.end()) + CRITICAL_BLOCK(cs_KeyStore) { - keyOut.SetSecret((*mi).second); - return true; + KeyMap::const_iterator mi = mapKeys.find(address); + if (mi != mapKeys.end()) + { + keyOut.SetSecret((*mi).second); + return true; + } } return false; } @@ -58,15 +65,7 @@ private: bool fUseCrypto; protected: - bool SetCrypted() - { - if (fUseCrypto) - return true; - if (!mapKeys.empty()) - return false; - fUseCrypto = true; - return true; - } + bool SetCrypted(); // will encrypt previously unencrypted keys bool EncryptKeys(CKeyingMaterial& vMasterKeyIn); @@ -74,8 +73,6 @@ protected: bool Unlock(const CKeyingMaterial& vMasterKeyIn); public: - mutable CCriticalSection cs_vMasterKey; //No guarantees master key wont get locked before you can use it, so lock this first - CCryptoKeyStore() : fUseCrypto(false) { } @@ -89,18 +86,20 @@ public: { if (!IsCrypted()) return false; - return vMasterKey.empty(); + bool result; + CRITICAL_BLOCK(cs_KeyStore) + result = vMasterKey.empty(); + return result; } bool Lock() { - CRITICAL_BLOCK(cs_vMasterKey) - { - if (!SetCrypted()) - return false; + if (!SetCrypted()) + return false; + CRITICAL_BLOCK(cs_KeyStore) vMasterKey.clear(); - } + return true; } @@ -109,9 +108,12 @@ public: bool AddKey(const CKey& key); bool HaveKey(const CBitcoinAddress &address) const { - if (!IsCrypted()) - return CBasicKeyStore::HaveKey(address); - return mapCryptedKeys.count(address) > 0; + CRITICAL_BLOCK(cs_KeyStore) + { + if (!IsCrypted()) + return CBasicKeyStore::HaveKey(address); + return mapCryptedKeys.count(address) > 0; + } } bool GetKey(const CBitcoinAddress &address, CKey& keyOut) const; bool GetPubKey(const CBitcoinAddress &address, std::vector<unsigned char>& vchPubKeyOut) const; |