Browse Source

add_stored() for config_passphrase_for_new_keys()

synchronous
Volker Birk 5 years ago
parent
commit
55c1fae17f
  1. 9
      passphrase_cache.cc
  2. 6
      passphrase_cache.hh

9
passphrase_cache.cc

@ -46,6 +46,12 @@ namespace pEp {
return "";
}
const char *PassphraseCache::add_stored(const std::string& passphrase)
{
_stored = passphrase;
return _stored.c_str();
}
bool PassphraseCache::for_each_passphrase(const passphrase_callee& callee)
{
std::lock_guard<std::mutex> lock(_mtx);
@ -54,6 +60,9 @@ namespace pEp {
if (callee(""))
return true;
if (callee(_stored))
return true;
for (auto entry=_cache.begin(); entry!=_cache.end(); ++entry) {
if (callee(entry->passphrase)) {
refresh(entry);

6
passphrase_cache.hh

@ -23,7 +23,8 @@ namespace pEp {
};
using cache = std::list<cache_entry>;
cache _cache;
cache _cache;
std::string _stored;
std::mutex _mtx;
size_t _max_size;
duration _timeout;
@ -47,6 +48,9 @@ namespace pEp {
// returns a ptr to the passsword entry in the cache. Don't free() it!
const char *add(const std::string& passphrase);
// adds the stored passphrase to the cache, which will not timeout
const char *add_stored(const std::string& passphrase);
// get all passphrases in cache from latest to oldest one by each call
// this function is throwing PassphraseCache::Empty when cache is empty
// and PassphraseCache::Exhausted when no passphrases are left, then

Loading…
Cancel
Save