diff --git a/passphrase_cache.cc b/passphrase_cache.cc index 210a94e..7e96a87 100644 --- a/passphrase_cache.cc +++ b/passphrase_cache.cc @@ -51,12 +51,12 @@ namespace pEp { if (_cache.empty()) { _which = _cache.end(); - throw std::underflow_error("empty passphrase cache"); + throw Empty(); } if (_which == _cache.begin()) { _which = _cache.end(); - throw std::underflow_error("out of passphrases"); + throw Exhausted(); } --_which; diff --git a/passphrase_cache.hh b/passphrase_cache.hh index 22334f9..42ffb32 100644 --- a/passphrase_cache.hh +++ b/passphrase_cache.hh @@ -31,6 +31,11 @@ namespace pEp { cache::iterator _which; public: + struct Empty : public std::underflow_error { + Empty() : std::underflow_error("passphrase cache empty") { } + struct Exhausted : public std::underflow_error { + Exhausted() : std::underflow_error("out of passphrases") { } + PassphraseCache(int max_size=20, duration timeout = std::chrono::minutes(10)) : _max_size(max_size), _timeout(timeout), _which(_cache.end()) { }