From a2ccfac61a5415f2a33dd470c76dcd650fc625c6 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 4 Apr 2023 15:55:19 +0200 Subject: [PATCH] Fix: Re-Add the original function 'import_key' has been removed by changing it to use 'import_key_with_fpr' --- src/pEp/_pEp/basic_api.cc | 25 +++++++++++++++++++++++++ src/pEp/_pEp/basic_api.hh | 2 ++ src/pEp/_pEp/pEpmodule.cc | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/src/pEp/_pEp/basic_api.cc b/src/pEp/_pEp/basic_api.cc index 989e3f5..87c20a9 100644 --- a/src/pEp/_pEp/basic_api.cc +++ b/src/pEp/_pEp/basic_api.cc @@ -109,6 +109,31 @@ namespace pEp { _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) { + 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) { diff --git a/src/pEp/_pEp/basic_api.hh b/src/pEp/_pEp/basic_api.hh index 542d079..1320be4 100644 --- a/src/pEp/_pEp/basic_api.hh +++ b/src/pEp/_pEp/basic_api.hh @@ -23,6 +23,8 @@ namespace pEp { void key_reset_trust(Identity ident); + 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 f6ae881..983c92b 100644 --- a/src/pEp/_pEp/pEpmodule.cc +++ b/src/pEp/_pEp/pEpmodule.cc @@ -624,6 +624,12 @@ namespace pEp { "reset trust bit or explicitly mistrusted status for an identity and " "its accompanying key/user_id pair\n"); + def("import_key", + &import_key, + "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"