|
@ -10,13 +10,14 @@ namespace pEp { |
|
|
{ } |
|
|
{ } |
|
|
|
|
|
|
|
|
PassphraseCache::PassphraseCache(size_t max_size, duration timeout) : |
|
|
PassphraseCache::PassphraseCache(size_t max_size, duration timeout) : |
|
|
_max_size{max_size}, _timeout{timeout}, first_time(true) |
|
|
_max_size{max_size}, _timeout{timeout}, _which(_cache.end()), |
|
|
|
|
|
first_time(true) |
|
|
{ } |
|
|
{ } |
|
|
|
|
|
|
|
|
PassphraseCache::PassphraseCache(const PassphraseCache& second) : |
|
|
PassphraseCache::PassphraseCache(const PassphraseCache& second) : |
|
|
_cache{second._cache}, _max_size{second._max_size}, |
|
|
_cache{second._cache}, _max_size{second._max_size}, |
|
|
_timeout{second._timeout}, _stored{second._stored}, |
|
|
_timeout{second._timeout}, _stored{second._stored}, |
|
|
first_time(true) |
|
|
_which(_cache.end()), first_time(true) |
|
|
{ |
|
|
{ |
|
|
cleanup(); |
|
|
cleanup(); |
|
|
} |
|
|
} |
|
@ -94,28 +95,28 @@ namespace pEp { |
|
|
_cache.splice(_cache.end(), _cache, entry); |
|
|
_cache.splice(_cache.end(), _cache, entry); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const char *PassphraseCache::latest_passphrase() |
|
|
const char *PassphraseCache::latest_passphrase(PassphraseCache& c) |
|
|
{ |
|
|
{ |
|
|
if (first_time) { |
|
|
if (c.first_time) { |
|
|
cleanup(); |
|
|
c.cleanup(); |
|
|
_which = _cache.end(); |
|
|
c._which = c._cache.end(); |
|
|
first_time = false; |
|
|
c.first_time = false; |
|
|
if (!_stored.empty()) |
|
|
if (!c._stored.empty()) |
|
|
return _stored.c_str(); |
|
|
return c._stored.c_str(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_cache.empty()) { |
|
|
if (c._cache.empty()) { |
|
|
first_time = true; |
|
|
c.first_time = true; |
|
|
throw Empty(); |
|
|
throw Empty(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_which == _cache.begin()) { |
|
|
if (c._which == c._cache.begin()) { |
|
|
first_time = true; |
|
|
c.first_time = true; |
|
|
throw Exhausted(); |
|
|
throw Exhausted(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
--_which; |
|
|
--c._which; |
|
|
return _which->passphrase.c_str(); |
|
|
return c._which->passphrase.c_str(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PEP_STATUS PassphraseCache::config_next_passphrase(bool reset) |
|
|
PEP_STATUS PassphraseCache::config_next_passphrase(bool reset) |
|
@ -134,7 +135,7 @@ namespace pEp { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
::config_passphrase(Adapter::session(), _copy.latest_passphrase()); |
|
|
::config_passphrase(Adapter::session(), latest_passphrase(_copy)); |
|
|
return PEP_STATUS_OK; |
|
|
return PEP_STATUS_OK; |
|
|
} |
|
|
} |
|
|
catch (pEp::PassphraseCache::Empty&) { |
|
|
catch (pEp::PassphraseCache::Empty&) { |
|
|