diff --git a/src/basic_api.cc b/src/basic_api.cc index 46ef3d8..d640f5e 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -83,7 +83,8 @@ namespace pEp { _throw_status(status); } - void key_reset_trust(Identity ident) { + void key_reset_trust(Identity ident) + { if (ident.fpr() == "") throw invalid_argument("address needed"); if (ident.address() == "") @@ -94,6 +95,25 @@ namespace pEp { PEP_STATUS status = key_reset_trust(adapter.session(), ident); _throw_status(status); } + + boost::python::list import_key(string key_data) + { + ::identity_list *private_keys = NULL; + PEP_STATUS status = ::import_key(adapter.session(), key_data.c_str(), key_data.size(), &private_keys); + if (status && status != PEP_KEY_IMPORTED) + _throw_status(status); + + auto result = boost::python::list(); + for (::identity_list *il = private_keys; il && il->ident; il=il->next) { + ::pEp_identity *ident = ::identity_dup(il->ident); + if (!ident) + throw bad_alloc(); + result.append(Identity(ident)); + il = il->next; + } + + return result; + } } } diff --git a/src/basic_api.hh b/src/basic_api.hh index e5281b7..57cd94c 100644 --- a/src/basic_api.hh +++ b/src/basic_api.hh @@ -20,6 +20,8 @@ namespace pEp { void unset_identity_flags(Identity ident, identity_flags_t flags); void key_reset_trust(Identity ident); + + boost::python::list import_key(string key_data); } } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 2d6c26d..f9b6d3c 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -393,6 +393,12 @@ BOOST_PYTHON_MODULE(pEp) "its accompanying key/user_id pair\n" ); + def("import_key", &pEp::PythonAdapter::import_key, + "private_key_list = import_key(key_data)\n" + "\n" + "import key(s) from key_data\n" + ); + // message API enum_("PEP_rating")