From 55c1fae17f7b0f840ed31a5c2b1c79e3c52b196c Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Thu, 2 Jul 2020 16:44:59 +0200 Subject: [PATCH] add_stored() for config_passphrase_for_new_keys() --- passphrase_cache.cc | 9 +++++++++ passphrase_cache.hh | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/passphrase_cache.cc b/passphrase_cache.cc index 00b2205..55b677f 100644 --- a/passphrase_cache.cc +++ b/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 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); diff --git a/passphrase_cache.hh b/passphrase_cache.hh index 525adfc..99ab574 100644 --- a/passphrase_cache.hh +++ b/passphrase_cache.hh @@ -23,7 +23,8 @@ namespace pEp { }; using cache = std::list; - 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