diff --git a/src/pEp/_pEp/basic_api.cc b/src/pEp/_pEp/basic_api.cc index d40d3af..5afbc4e 100644 --- a/src/pEp/_pEp/basic_api.cc +++ b/src/pEp/_pEp/basic_api.cc @@ -110,7 +110,32 @@ namespace pEp { _throw_status(status); } - boost::python::tuple import_key(string key_data) + 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) { + free_identity_list(private_keys); + throw std::bad_alloc(); + } + result.append(Identity(ident)); + } + + free_identity_list(private_keys); + return result; + } + + boost::python::tuple import_key_with_fpr_return(string key_data) { ::identity_list *private_keys = NULL; ::stringlist_t *imported_keys = NULL; diff --git a/src/pEp/_pEp/basic_api.hh b/src/pEp/_pEp/basic_api.hh index 1518cb4..579c007 100644 --- a/src/pEp/_pEp/basic_api.hh +++ b/src/pEp/_pEp/basic_api.hh @@ -23,7 +23,9 @@ namespace pEp { void key_reset_trust(Identity ident); - boost::python::tuple import_key(string key_data); + boost::python::list import_key(string key_data); + + boost::python::tuple import_key_with_fpr_return(string key_data); string export_key(Identity ident); diff --git a/src/pEp/_pEp/pEpmodule.cc b/src/pEp/_pEp/pEpmodule.cc index 13f0d6a..77d3231 100644 --- a/src/pEp/_pEp/pEpmodule.cc +++ b/src/pEp/_pEp/pEpmodule.cc @@ -650,10 +650,19 @@ namespace pEp { def("import_key", &import_key, - "imported_keys, affected_own_identities = import_key(key_data)\n" + "private_key_list = import_key(key_data)\n" "\n" "import key(s) from key_data\n"); + def("import_key_with_fpr_return", + &import_key_with_fpr_return, + "imported_keys, affected_own_identities = import_key_with_fpr_return(key_data)\n" + "\n" + "import key(s) from key_data\n" + "\n" + "imported_keys a list of FPRs\n" + "affected_own_identities the list of modified own identities\n"); + def("export_key", &export_key, "key_data = export_key(identity)\n"