|
|
@ -1,20 +1,24 @@ |
|
|
|
#include "framework.hh" |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <unistd.h> |
|
|
|
#include <assert.h> |
|
|
|
|
|
|
|
#include <sys/param.h> |
|
|
|
#include <passphrase_cache.hh> |
|
|
|
#include <status_to_string.hh> |
|
|
|
#include <Adapter.hh> |
|
|
|
|
|
|
|
#include "framework.hh" |
|
|
|
#include "passphrase_cache.hh" |
|
|
|
#include "status_to_string.hh" |
|
|
|
using namespace pEp; |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
PEP_STATUS api_test1(PEP_SESSION session, const char *str, char *bytes, int n, ::stringlist_t *sl) |
|
|
|
::PEP_STATUS api_test1(::PEP_SESSION session, const char *str, char *bytes, int n, ::stringlist_t *sl) |
|
|
|
{ |
|
|
|
std::cout << "called api_test1\n"; |
|
|
|
return PEP_WRONG_PASSPHRASE; |
|
|
|
} |
|
|
|
|
|
|
|
PEP_STATUS api_test2(PEP_SESSION session, int n, const char *str, char *bytes, ::stringlist_t *sl) |
|
|
|
::PEP_STATUS api_test2(::PEP_SESSION session, int n, const char *str, char *bytes, ::stringlist_t *sl) |
|
|
|
{ |
|
|
|
std::cout << "called api_test2\n"; |
|
|
|
return PEP_STATUS_OK; |
|
|
@ -23,14 +27,14 @@ PEP_STATUS api_test2(PEP_SESSION session, int n, const char *str, char *bytes, : |
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|
{ |
|
|
|
pEp::Test::setup(argc, argv); |
|
|
|
Test::setup(argc, argv); |
|
|
|
|
|
|
|
const char *str = "23"; |
|
|
|
char *bytes = NULL; |
|
|
|
int n = 42; |
|
|
|
::stringlist_t *sl = NULL; |
|
|
|
|
|
|
|
pEp::PassphraseCache cache{ 2, std::chrono::seconds(1) }; |
|
|
|
PassphraseCache cache{ 2, std::chrono::seconds(1) }; |
|
|
|
cache.add("say"); |
|
|
|
cache.add("hello"); |
|
|
|
cache.add("world"); |
|
|
@ -53,21 +57,15 @@ int main(int argc, char **argv) |
|
|
|
return false; |
|
|
|
}); |
|
|
|
|
|
|
|
PEP_STATUS status = cache.api( |
|
|
|
api_test1, |
|
|
|
pEp::Adapter::session(), |
|
|
|
"23", |
|
|
|
bytes, |
|
|
|
n, |
|
|
|
(::stringlist_t *)NULL); |
|
|
|
::PEP_STATUS status = cache.api(api_test1, Adapter::session(), "23", bytes, n, (::stringlist_t *)NULL); |
|
|
|
assert(status == PEP_WRONG_PASSPHRASE); |
|
|
|
status = cache.api(api_test2, pEp::Adapter::session(), n, str, bytes, sl); |
|
|
|
status = cache.api(api_test2, Adapter::session(), n, str, bytes, sl); |
|
|
|
assert(status == PEP_STATUS_OK); |
|
|
|
|
|
|
|
cache.add("hello"); |
|
|
|
cache.add("world"); |
|
|
|
std::cout << "expected: two passphrases in reverse order\n"; |
|
|
|
pEp::PassphraseCache _cache = cache; |
|
|
|
PassphraseCache _cache = cache; |
|
|
|
try { |
|
|
|
while (1) { |
|
|
|
std::cout << "'" << _cache.latest_passphrase(_cache) << "'\n"; |
|
|
@ -75,12 +73,12 @@ int main(int argc, char **argv) |
|
|
|
} catch (std::underflow_error &) { |
|
|
|
} |
|
|
|
|
|
|
|
pEp::passphrase_cache.add("hello"); |
|
|
|
pEp::passphrase_cache.add("world"); |
|
|
|
passphrase_cache.add("hello"); |
|
|
|
passphrase_cache.add("world"); |
|
|
|
std::cout << "two times PEP_STATUS_OK (0), one time PEP_WRONG_PASSPHRASE (2561)\n"; |
|
|
|
do { |
|
|
|
status = pEp::PassphraseCache::config_next_passphrase(); |
|
|
|
std::cout << pEp::status_to_string(status) << " (" << status << ")\n"; |
|
|
|
status = PassphraseCache::config_next_passphrase(); |
|
|
|
std::cout << status_to_string(status) << " (" << status << ")\n"; |
|
|
|
} while (status == PEP_STATUS_OK); |
|
|
|
|
|
|
|
sleep(2); |
|
|
@ -91,11 +89,11 @@ int main(int argc, char **argv) |
|
|
|
return false; |
|
|
|
}); |
|
|
|
|
|
|
|
status = cache.api(api_test1, pEp::Adapter::session(), str, bytes, n, sl); |
|
|
|
status = cache.api(api_test1, Adapter::session(), str, bytes, n, sl); |
|
|
|
assert(status == PEP_WRONG_PASSPHRASE); |
|
|
|
status = cache.api(api_test2, pEp::Adapter::session(), 23, str, bytes, sl); |
|
|
|
status = cache.api(api_test2, Adapter::session(), 23, str, bytes, sl); |
|
|
|
assert(status == PEP_STATUS_OK); |
|
|
|
|
|
|
|
pEp::Adapter::session(pEp::Adapter::release); |
|
|
|
Adapter::session(Adapter::release); |
|
|
|
return 0; |
|
|
|
} |
|
|
|