diff --git a/src/basic_api.cc b/src/basic_api.cc index b2be618..e713da0 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -6,6 +6,8 @@ namespace pEp { namespace PythonAdapter { void update_identity(Identity& ident) { + if (ident.address() == "") + throw invalid_argument("address needed"); if (ident.me()) throw runtime_error("update_identity: not for own identities"); if (ident.user_id() == PEP_OWN_USERID) @@ -18,12 +20,49 @@ namespace pEp { void myself(Identity& ident) { + if (ident.address() == "") + throw invalid_argument("address needed"); + if (ident.username() == "") + throw invalid_argument("username needed"); + if (!(ident.user_id() == "" || ident.user_id() == PEP_OWN_USERID)) + throw invalid_argument("user_id must be empty or '" PEP_OWN_USERID "'"); + ident.me(true); ident.user_id(PEP_OWN_USERID); PEP_STATUS status = myself(session, ident); _throw_status(status); } + + string _trustwords(Identity me, Identity partner, string lang) + { + if (me.fpr() == "" || partner.fpr() == "") + throw invalid_argument("fingerprint needed in Identities"); + + if (lang == "" && me.lang() == partner.lang()) + lang = me.lang(); + + char *words = NULL; + size_t size = 0; + PEP_STATUS status = trustwords(session, me.fpr().c_str(), + lang.c_str(), &words, &size, 5); + _throw_status(status); + string my_words = words; + + free(words); + words = NULL; + size = 0; + status = trustwords(session, partner.fpr().c_str(), lang.c_str(), + &words, &size, 5); + _throw_status(status); + string partner_words = words; + free(words); + + if (me.fpr() > partner.fpr()) + return partner_words + my_words; + else + return my_words + partner_words; + } } } diff --git a/src/basic_api.hh b/src/basic_api.hh index b6bd1ae..ca4b33f 100644 --- a/src/basic_api.hh +++ b/src/basic_api.hh @@ -6,6 +6,7 @@ namespace pEp { namespace PythonAdapter { void update_identity(Identity& ident); void myself(Identity& ident); + string _trustwords(Identity me, Identity partner, string lang); } } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 9f53c5b..6725b94 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -196,6 +196,7 @@ BOOST_PYTHON_MODULE(pEp) // message API def("color", &_color, "calculate color value out of rating"); + def("trustwords", &_trustwords, "calculate trustwords for two Identities"); // key sync API