Browse Source

messageToSend() cache handler

synchronous
Volker Birk 5 years ago
parent
commit
f05dc2700c
  1. 22
      passphrase_cache.cc
  2. 20
      passphrase_cache.hh

22
passphrase_cache.cc

@ -81,5 +81,27 @@ namespace pEp {
--_which; --_which;
return _which->passphrase.c_str(); return _which->passphrase.c_str();
} }
PEP_STATUS PassphraseCache::messageToSend(PassphraseCache&& cache, PEP_SESSION session)
{
static pEp::PassphraseCache _copy;
static bool new_copy = true;
if (new_copy) {
_copy = cache;
new_copy = false;
}
try {
::config_passphrase(session, _copy.latest_passphrase());
return PEP_STATUS_OK;
}
catch (pEp::PassphraseCache::Empty&) {
new_copy = true;
return PEP_PASSPHRASE_REQUIRED;
}
catch (pEp::PassphraseCache::Exhausted&) {
new_copy = true;
return PEP_WRONG_PASSPHRASE;
}
}
}; };

20
passphrase_cache.hh

@ -48,6 +48,19 @@ namespace pEp {
const char *add(std::string passphrase); const char *add(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
// starts over
const char *latest_passphrase();
// call this function inside the messageToSend() implementation of the adapter
// this function is using latest_passphrase() to test one passphrase after the
// other until the cache is exhausted
static PEP_STATUS messageToSend(PassphraseCache&& cache, PEP_SESSION session);
// for each passphrase call the callee until it returns true for a // for each passphrase call the callee until it returns true for a
// matching passphrase or no passphrases are left // matching passphrase or no passphrases are left
// always tests empty passphrase first // always tests empty passphrase first
@ -56,13 +69,6 @@ namespace pEp {
using passphrase_callee = std::function<bool(std::string)>; using passphrase_callee = std::function<bool(std::string)>;
bool for_each_passphrase(const passphrase_callee& callee); bool for_each_passphrase(const passphrase_callee& callee);
// 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
// starts over
const char *latest_passphrase();
// convenience functions // convenience functions
// i.e. // i.e.
// status = cache.api(::encrypt_message, session, src, extra, dst, enc_format, flags) // status = cache.api(::encrypt_message, session, src, extra, dst, enc_format, flags)

Loading…
Cancel
Save