diff --git a/src/identity.cc b/src/identity.cc index ea9ba34..4bec195 100644 --- a/src/identity.cc +++ b/src/identity.cc @@ -1,7 +1,10 @@ #include "Identity.hh" +#include "pEpmodule.hh" +#include "message_api.hh" #include #include #include +#include namespace pEp { namespace PythonAdapter { @@ -111,6 +114,23 @@ namespace pEp { return _ident->lang; } + int Identity::rating() + { + if (!(_ident->address)) + throw invalid_argument("address must be given"); + + PEP_rating rating = PEP_rating_undefined; + PEP_STATUS status = identity_rating(session, _ident, &rating); + _throw_status(status); + + return (int) rating; + } + + int Identity::color() + { + return _color(rating()); + } + Identity identity_attr(pEp_identity *&ident) { pEp_identity *_dup; diff --git a/src/identity.hh b/src/identity.hh index a08f228..a3237ca 100644 --- a/src/identity.hh +++ b/src/identity.hh @@ -51,6 +51,9 @@ namespace pEp { identity_flags_t flags() { return _ident->flags; } void flags(identity_flags_t flags) { _ident->flags = flags; } + + int rating(); + int color(); }; Identity identity_attr(pEp_identity *&ident); diff --git a/src/message.cc b/src/message.cc index 427b5f1..0ba306e 100644 --- a/src/message.cc +++ b/src/message.cc @@ -6,6 +6,7 @@ #include #include #include +#include namespace pEp { namespace PythonAdapter { @@ -294,6 +295,25 @@ namespace pEp { tuple Message::decrypt() { return decrypt_message(*this); } + + int Message::outgoing_rating() + { + if (!(_msg && _msg->from)) + throw invalid_argument("from must be a valid Identity()"); + if (!(_msg && _msg->dir == PEP_dir_outgoing)) + throw invalid_argument("Message.dir must be outgoing"); + + PEP_rating rating = PEP_rating_undefined; + PEP_STATUS status = outgoing_message_rating(session, _msg, &rating); + _throw_status(status); + + return (int) rating; + } + + int Message::outgoing_color() + { + return _color(outgoing_rating()); + } } } diff --git a/src/message.hh b/src/message.hh index ea9ee32..db78ceb 100644 --- a/src/message.hh +++ b/src/message.hh @@ -127,6 +127,8 @@ namespace pEp { Message encrypt(list extra); Message encrypt(); tuple decrypt(); + int outgoing_rating(); + int outgoing_color(); }; } } diff --git a/src/message_api.cc b/src/message_api.cc index d5b59c2..6831191 100644 --- a/src/message_api.cc +++ b/src/message_api.cc @@ -56,7 +56,7 @@ namespace pEp { return make_tuple(dst, keylist, rating, flags); } - int color_from_rating(int rating) + int _color(int rating) { return (int) ::color_from_rating((PEP_rating) rating); } diff --git a/src/message_api.hh b/src/message_api.hh index 0d69a4c..39f968e 100644 --- a/src/message_api.hh +++ b/src/message_api.hh @@ -7,7 +7,7 @@ namespace pEp { Message encrypt_message(Message src, list extra = list(), int enc_format = 4, int flags = 0); tuple decrypt_message(Message src); - int color_from_rating(int rating); + int _color(int rating); } } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 6f6e42d..9f53c5b 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -90,7 +90,9 @@ BOOST_PYTHON_MODULE(pEp) "true if own identity, false otherwise") .add_property("flags", (identity_flags_t(Identity::*)()) &Identity::flags, (void(Identity::*)(identity_flags_t)) &Identity::flags, - "flags (p≡p internal)"); + "flags (p≡p internal)") + .add_property("rating", &Identity::rating, "rating of Identity") + .add_property("color", &Identity::color, "color of Identity"); identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId"; @@ -182,7 +184,9 @@ BOOST_PYTHON_MODULE(pEp) .def("encrypt", (Message(Message::*)(list))&Message::encrypt, "encrypt message") .def("encrypt", (Message(Message::*)(list,int))&Message::encrypt, "encrypt message") .def("encrypt", (Message(Message::*)(list,int,int))&Message::encrypt, "encrypt message") - .def("decrypt", &Message::decrypt, "decrypt message"); + .def("decrypt", &Message::decrypt, "decrypt message") + .add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have") + .add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have"); // basic API @@ -191,9 +195,7 @@ BOOST_PYTHON_MODULE(pEp) // message API - def("encrypt_message", &encrypt_message, "encrypt message in memory"); - def("decrypt_message", &decrypt_message, "decrypt message in memory"); - def("color_from_rating", &color_from_rating, "calculate color value"); + def("color", &_color, "calculate color value out of rating"); // key sync API