From 0ca729dd2a8bd4b5f7e2b70bbc65a6c9d0bde78c Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 15 Jan 2020 01:39:19 +0100 Subject: [PATCH] add set_own_key(me, fpr) to Basic API --- src/basic_api.cc | 24 +++++++++++++++++++++--- src/basic_api.hh | 2 +- src/pEpmodule.cc | 19 +++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index af7575e..8baebe2 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -49,7 +49,7 @@ namespace pEp { _throw_status(status); return words; } - + void trust_personal_key(Identity ident) { if (ident.fpr() == "") @@ -82,7 +82,7 @@ namespace pEp { PEP_STATUS status = unset_identity_flags(adapter.session(), ident, flags); _throw_status(status); } - + void key_reset_trust(Identity ident) { if (ident.fpr() == "") @@ -96,6 +96,8 @@ namespace pEp { _throw_status(status); } + + boost::python::list import_key(string key_data) { ::identity_list *private_keys = NULL; @@ -116,6 +118,22 @@ namespace pEp { free_identity_list(private_keys); return result; } + + void set_own_key(Identity& ident, string fpr) + { + if (ident.address() == "") + throw invalid_argument("address needed"); + if (ident.username() == "") + throw invalid_argument("username needed"); + if (ident.user_id() == "") + throw invalid_argument("user_id needed"); + if (fpr == "") + throw invalid_argument("fpr needed"); + + + const char* fpr_c = fpr.c_str(); + PEP_STATUS status = set_own_key(adapter.session(), ident, fpr_c); + _throw_status(status); + } } } - diff --git a/src/basic_api.hh b/src/basic_api.hh index f532ee2..4be530a 100644 --- a/src/basic_api.hh +++ b/src/basic_api.hh @@ -18,6 +18,6 @@ namespace pEp { void key_reset_trust(Identity ident); boost::python::list import_key(string key_data); + void set_own_key(Identity& ident, string fpr); } } - diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index d3ed6a6..166f2db 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -138,7 +138,7 @@ BOOST_PYTHON_MODULE(pEp) scope().attr("per_machine_directory") = per_machine_directory(); scope().attr("engine_version") = get_engine_version(); scope().attr("protocol_version") = get_protocol_version(); - + def("passive_mode", pEp::PythonAdapter::config_passive_mode, "do not attach pub keys to all messages"); @@ -227,7 +227,7 @@ BOOST_PYTHON_MODULE(pEp) .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy) .def("update", &pEp::PythonAdapter::Identity::update, "update Identity") .def("__copy__", &pEp::PythonAdapter::Identity::copy); - + identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId"; auto blob_class = class_("Blob", @@ -425,6 +425,21 @@ BOOST_PYTHON_MODULE(pEp) "import key(s) from key_data\n" ); + def("set_own_key", &pEp::PythonAdapter::set_own_key, + "set_own_key(me, fpr)\n" + "\n" + "mark a key as an own key, and make it the default key\n" + "\n" + "me Own identity for which to add the existing key\n" + "fpr The fingerprint of the key to be added\n" + "\n" + "me->address, me->user_id and me->username must be set to valid data\n" + "myself() is called by set_own_key() without key generation\n" + "me->flags are ignored\n" + "me->address must not be an alias\n" + "me->fpr will be ignored and replaced by fpr\n" + ); + // message API enum_("PEP_rating")