Compare commits
22 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
16e9bda15f | 4 years ago |
![]() |
348fa8f2f9 | 4 years ago |
![]() |
8e1898446e | 4 years ago |
![]() |
da1d3a8347 | 4 years ago |
![]() |
103208ea95 | 4 years ago |
![]() |
7a84853814 | 4 years ago |
![]() |
d87fd19652 | 4 years ago |
![]() |
784653df6f | 4 years ago |
![]() |
6a1d302821 | 5 years ago |
![]() |
dc0b769136 | 5 years ago |
![]() |
119effbfdb | 5 years ago |
![]() |
7b4ba8b4c4 | 5 years ago |
![]() |
b153ce3c7a | 5 years ago |
![]() |
2e138e1190 | 5 years ago |
![]() |
0792869686 | 5 years ago |
![]() |
c56b3b40f3 | 5 years ago |
![]() |
19b2ebb18d | 5 years ago |
![]() |
0e896bf36c | 5 years ago |
![]() |
0e893624c9 | 5 years ago |
![]() |
63e830040c | 5 years ago |
![]() |
688fff5667 | 5 years ago |
![]() |
8aa36d9f95 | 5 years ago |
37 changed files with 2381 additions and 2024 deletions
@ -0,0 +1,8 @@ |
|||
Module pEp._gen |
|||
--------------- |
|||
.. automodule:: pEp._gen |
|||
:members: |
|||
:imported-members: |
|||
:undoc-members: |
|||
:show-inheritance: |
|||
|
@ -0,0 +1,7 @@ |
|||
Module pEp._pEp |
|||
--------------- |
|||
.. automodule:: pEp._pEp |
|||
:members: |
|||
:imported-members: |
|||
:undoc-members: |
|||
:show-inheritance: |
@ -0,0 +1,2 @@ |
|||
pEpACIDgen |
|||
pyBind11 |
@ -0,0 +1,16 @@ |
|||
HERE:=$(dir $(lastword $(MAKEFILE_LIST))) |
|||
-include $(HERE)../../local.conf |
|||
|
|||
TARGET_PEP=_pEp.so |
|||
TARGET_GEN=_gen.so |
|||
|
|||
# General Build settings
|
|||
CXX=g++ |
|||
CXXFLAGS+=-std=c++11 -g |
|||
INCLUDES+=-I$(PREFIX)/include |
|||
INCLUDES+=-I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 |
|||
LIB_DIRS=-L$(PREFIX)/lib |
|||
LIB_DIRS+=-L/opt/local/lib |
|||
LIBS=-lpEpEngine -lpEpAdapter |
|||
LDFLAGS+=-undefined dynamic_lookup |
|||
|
@ -0,0 +1,46 @@ |
|||
include Makefile.conf |
|||
|
|||
TARGET=_gen.so |
|||
|
|||
# Swap here, for static vs dyn linking
|
|||
TARGET_MODULE_DYN=$(TARGET) |
|||
TARGET_MODULE_STATIC= |
|||
|
|||
CXX=clang |
|||
CXXFLAGS+=-std=c++11 -g |
|||
|
|||
SRCS+=$(wildcard *.cc) |
|||
OBJS+=$(SRCS:.cc=.o) |
|||
|
|||
CXXFLAGS+=$(INCLUDES) |
|||
LDFLAGS_DYN+=-undefined dynamic_lookup $(LIBS_PATH) $(LIBS) |
|||
LDFLAGS_STATIC+=-undefined dynamic_lookup |
|||
|
|||
$(info -----BUILD INFO----) |
|||
$(info SRCS $(SRCS)) |
|||
$(info OBJS $(OBJS)) |
|||
|
|||
.PHONY: all gen gen-pybind module_dyn module_static clean |
|||
|
|||
all: gen compile |
|||
|
|||
gen: |
|||
$(MAKE) -C gen |
|||
|
|||
gen-pybind: |
|||
$(MAKE) -C gen pybind |
|||
|
|||
compile: $(TARGET) |
|||
|
|||
$(TARGET_MODULE_DYN) : $(OBJS) |
|||
$(CXX) $(LDFLAGS_DYN) -o $@ $^ |
|||
|
|||
$(TARGET_MODULE_STATIC) : $(OBJS) $(LIBS_STATIC) |
|||
$(CXX) $(LDFLAGS_STATIC) -o $@ $^ |
|||
|
|||
clean: |
|||
rm -f $(TARGET) |
|||
rm -f $(OBJS) |
|||
|
|||
clean-all: clean |
|||
$(MAKE) -C gen clean |
@ -0,0 +1,12 @@ |
|||
# pyBind11 and python headers
|
|||
INCLUDES+=$(shell pybind11-config --includes) |
|||
|
|||
# example lib
|
|||
INCLUDES+=-I/Users/heck/local-default/include/ |
|||
|
|||
# static lib (.a)
|
|||
#LIBS_STATIC+=/Users/heck/local-default/include/
|
|||
|
|||
# dynamic lib (.so)
|
|||
LIBS+=-lpEpEngine |
|||
LIBS_PATH+=-L/Users/heck/local-default/lib |
@ -0,0 +1,40 @@ |
|||
// This file is under GNU Affero General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#ifndef ADAPTER_MAIN_HH |
|||
#define ADAPTER_MAIN_HH |
|||
|
|||
// Use only if cant be avoided
|
|||
//#include <pEp/stringlist.h>
|
|||
|
|||
/// =======
|
|||
#include <pEp/pEpEngine.h> |
|||
//// Engine
|
|||
////pEp-API
|
|||
#include <pEp/keymanagement.h> |
|||
#include <pEp/message_api.h> |
|||
#include <pEp/sync_api.h> |
|||
#include <pEp/distribution_codec.h> |
|||
#include <pEp/sync_codec.h> |
|||
/// =======
|
|||
|
|||
// #include <pEp/identity_list.h>
|
|||
// #include <pEp/key_reset.h>
|
|||
// #include <pEp/mime.h>
|
|||
// #include <pEp/message.h>
|
|||
// #include <pEp/sync_codec.h>
|
|||
// #include <pEp/distribution_codec.h>
|
|||
// #include <pEp/timestamp.h>
|
|||
// #include <pEp/stringpair.h>
|
|||
|
|||
// libpEpAdapter
|
|||
/// =======
|
|||
//#include <pEp/Adapter.hh>
|
|||
//#include <pEp/callback_dispatcher.hh>
|
|||
/// =======
|
|||
|
|||
|
|||
// #include <pEp/status_to_string.hh>
|
|||
// #include <pEp/pEpLog.hh>
|
|||
|
|||
#endif // ADAPTER_MAIN_HH
|
@ -0,0 +1,35 @@ |
|||
include ../Makefile.conf |
|||
|
|||
YML2_FILE=py_module.yml2 |
|||
YSL2_FILE=$(shell pEp_acid_gen-config) |
|||
PYBIND11_FILE=py_module.pybind11 |
|||
DEBUG_AST_FILE=adapter_main.hh.ast.json |
|||
DEBUG_ACID_FILE=adapter_main.hh.acid.json |
|||
DEBUG_YML_FILE=adapter_main.hh.acid.yml |
|||
|
|||
$(info -----_gen GEN----) |
|||
$(info YML2_FILE $(YML2_FILE)) |
|||
$(info YSL2_FILE $(YSL2_FILE)) |
|||
$(info CC_FILE $(PYBIND11_FILE)) |
|||
|
|||
.PHONY = all yml pybind |
|||
|
|||
all: pybind |
|||
|
|||
yml: $(YML2_FILE) |
|||
|
|||
pybind: $(YML2_FILE) $(PYBIND11_FILE) |
|||
|
|||
$(YML2_FILE): config.json |
|||
pEp_acid_gen $^ |
|||
|
|||
$(PYBIND11_FILE) : $(YML2_FILE) |
|||
yml2proc --encoding=utf8 -y $(YSL2_FILE) $(YML2_FILE) |
|||
|
|||
clean: |
|||
rm -f $(YML2_FILE) |
|||
rm -f $(PYBIND11_FILE) |
|||
rm -f $(DEBUG_AST_FILE) |
|||
rm -f $(DEBUG_ACID_FILE) |
|||
rm -f $(DEBUG_YML_FILE) |
|||
|
@ -0,0 +1,98 @@ |
|||
{ |
|||
"module_name": "_gen", |
|||
"header_filename": "../adapter_main.hh", |
|||
"libclang_path": "/opt/local/libexec/llvm-9.0/lib/libclang.dylib", |
|||
"variables": [ |
|||
], |
|||
"functions": [ |
|||
"KEYMANAGEMENT", |
|||
"update_identity", |
|||
"myself", |
|||
"//register_examine_function", |
|||
"//do_keymanagement", |
|||
"key_mistrusted", |
|||
"trust_personal_key", |
|||
"trust_own_key", |
|||
"key_reset_trust", |
|||
"//own_key_is_listed", |
|||
"_own_identities_retrieve", |
|||
"own_identities_retrieve", |
|||
"_own_keys_retrieve", |
|||
"own_keys_retrieve", |
|||
"set_own_key", |
|||
"//clean_own_key_defaults", |
|||
|
|||
"//PEPENGINE", |
|||
"update_identity", |
|||
"myself", |
|||
"//register_examine_function", |
|||
"//do_keymanagement", |
|||
"key_mistrusted", |
|||
"trust_personal_key", |
|||
"trust_own_key", |
|||
"key_reset_trust", |
|||
"//own_key_is_listed", |
|||
"own_identities_retrieve", |
|||
"//own_keys_retrieve", |
|||
"set_own_key", |
|||
"//clean_own_key_defaults", |
|||
"new_identity", |
|||
|
|||
"//MESSAGE_API", |
|||
"encrypt_message", |
|||
"encrypt_message_and_add_priv_key", |
|||
"encrypt_message_for_self", |
|||
"color_from_rating", |
|||
"decrypt_message", |
|||
"own_message_private_key_details", |
|||
"outgoing_message_rating", |
|||
"outgoing_message_rating_preview", |
|||
"identity_rating", |
|||
"get_binary_path", |
|||
"get_trustwords", |
|||
"get_message_trustwords", |
|||
"get_trustwords_for_fprs", |
|||
"re_evaluate_message_rating", |
|||
"get_key_rating_for_user", |
|||
"rating_from_comm_type", |
|||
"probe_encrypt", |
|||
|
|||
"//MESSAGE", |
|||
"new_message", |
|||
"free_message", |
|||
"message_dup", |
|||
"message_transfer", |
|||
"new_message_ref_list", |
|||
"free_message_ref_list", |
|||
"message_ref_list_dup", |
|||
"message_ref_list_add", |
|||
|
|||
"//SYNC_API", |
|||
"deliverHandshakeResult", |
|||
"//register_sync_callbacks", |
|||
"//unregister_sync_callbacks", |
|||
"//do_sync_protocol", |
|||
"//do_sync_protocol_step", |
|||
"//is_sync_thread", |
|||
"//new_sync_timeout_event", |
|||
"enter_device_group", |
|||
"//leave_device_group", |
|||
"enable_identity_for_sync", |
|||
"disable_identity_for_sync", |
|||
|
|||
"//SYNC_CODEC", |
|||
"//decode_Sync_message", |
|||
"//encode_Sync_message", |
|||
"//PER_to_XER_Sync_msg", |
|||
"//XER_to_PER_Sync_msg", |
|||
|
|||
"//DISTRIBUTION_CODEC", |
|||
"//decode_Distribution_message", |
|||
"//encode_Distribution_message", |
|||
"//PER_to_XER_Distribution_msg", |
|||
"//XER_to_PER_Distribution_msg" |
|||
], |
|||
"debug_ast" : 0, |
|||
"debug_acid" : 0, |
|||
"debug_yml" : 0 |
|||
} |
@ -0,0 +1,22 @@ |
|||
#include <string> |
|||
#include <iostream> |
|||
#include <pybind11/pybind11.h> |
|||
#include <pybind11/detail/common.h> |
|||
#include "adapter_main.hh" |
|||
#include <pEp/Adapter.hh> |
|||
#include <pEp/callback_dispatcher.hh> |
|||
|
|||
using namespace std; |
|||
namespace alib = pEp::Adapter; |
|||
|
|||
PEP_SESSION pep_session() { |
|||
return alib::session(); |
|||
} |
|||
|
|||
PYBIND11_MODULE(_gen, m) { |
|||
|
|||
// PEP_SESSION
|
|||
// m.def("pep_session",(PEP_SESSION(*)()) &pep_session);
|
|||
|
|||
#include "gen/py_module.pybind11" |
|||
} |
@ -0,0 +1,32 @@ |
|||
include ../Makefile.conf |
|||
TARGET=$(TARGET_PEP) |
|||
|
|||
# Specific Build settings
|
|||
CXXFLAGS+=-Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -g -fwrapv -O3 -Wall -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk |
|||
INCLUDES+= |
|||
LIB_DIRS+= |
|||
LIBS+=-lboost_python38-mt -lboost_locale-mt |
|||
LDFLAGS+= |
|||
|
|||
|
|||
|
|||
# Combine Settings
|
|||
CXXFLAGS+=$(INCLUDES) |
|||
LDFLAGS+=$(LIB_DIRS) |
|||
LDFLAGS+=$(LIBS) |
|||
|
|||
SRCS:=$(wildcard *.cc) |
|||
OBJS:=$(SRCS:.cc=.o) |
|||
|
|||
.PHONY: clean |
|||
|
|||
all: $(TARGET) |
|||
|
|||
# Using implicit compile target
|
|||
# And explicit link taget
|
|||
$(TARGET): $(OBJS) |
|||
$(CXX) $(LDFLAGS) -o $@ $^ |
|||
|
|||
clean: |
|||
rm -rf $(TARGET) |
|||
rm -rf $(OBJS) |
@ -0,0 +1,163 @@ |
|||
// This file is under GNU Affero General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#include "adapter_main.hh" |
|||
#include "message.hh" |
|||
#include "message_api.hh" |
|||
|
|||
namespace pEp { |
|||
namespace PythonAdapter { |
|||
|
|||
|
|||
static const char *version_string = "p≡p Python adapter version 0.3"; |
|||
|
|||
void init_before_main_module() { |
|||
pEpLog("called"); |
|||
} |
|||
|
|||
// hidden init function, wrapped by hello_world.init()
|
|||
void _init_after_main_module() { |
|||
pEpLog("called"); |
|||
callback_dispatcher.add(_messageToSend, notifyHandshake, nullptr, nullptr); |
|||
Adapter::_messageToSend = CallbackDispatcher::messageToSend; |
|||
} |
|||
|
|||
void config_passive_mode(bool enable) { |
|||
::config_passive_mode(Adapter::session(), enable); |
|||
} |
|||
|
|||
void config_unencrypted_subject(bool enable) { |
|||
::config_unencrypted_subject(Adapter::session(), enable); |
|||
} |
|||
|
|||
void key_reset_user(const string &user_id, const string &fpr) { |
|||
if (user_id == "") { |
|||
throw invalid_argument("user_id required"); |
|||
} |
|||
|
|||
::PEP_STATUS status = ::key_reset_user(Adapter::session(), user_id.c_str(), fpr != "" ? fpr.c_str() : nullptr); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
void key_reset_user2(const string &user_id) { |
|||
key_reset_user(user_id, ""); |
|||
} |
|||
|
|||
void key_reset_all_own_keys() { |
|||
::PEP_STATUS status = ::key_reset_all_own_keys(Adapter::session()); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
string about() { |
|||
string version = string(version_string) + "\np≡p version " + PEP_VERSION + "\n"; |
|||
return version; |
|||
} |
|||
|
|||
void _throw_status(::PEP_STATUS status) { |
|||
if (status == ::PEP_STATUS_OK) { |
|||
return; |
|||
} |
|||
if (status >= 0x400 && status <= 0x4ff) { |
|||
return; |
|||
} |
|||
if (status == ::PEP_OUT_OF_MEMORY) { |
|||
throw bad_alloc(); |
|||
} |
|||
if (status == ::PEP_ILLEGAL_VALUE) { |
|||
throw invalid_argument("illegal value"); |
|||
} |
|||
|
|||
if (status_to_string(status) == "unknown status code") { |
|||
stringstream build; |
|||
build << setfill('0') << "p≡p 0x" << setw(4) << hex << status; |
|||
throw runtime_error(build.str()); |
|||
} else { |
|||
throw runtime_error(status_to_string(status)); |
|||
} |
|||
} |
|||
|
|||
::PEP_STATUS _messageToSend(::message *msg) { |
|||
pEpLog("called"); |
|||
try { |
|||
PyGILState_STATE gil = PyGILState_Ensure(); |
|||
pEpLog("GIL Aquired"); |
|||
bp::object modref = bp::import("pEp"); |
|||
bp::object funcref = modref.attr("message_to_send"); |
|||
bp::call<void>(funcref.ptr(), Message()); |
|||
PyGILState_Release(gil); |
|||
pEpLog("GIL released"); |
|||
} catch (exception &e) { |
|||
} |
|||
|
|||
return ::PEP_STATUS_OK; |
|||
} |
|||
|
|||
::PEP_STATUS notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal) { |
|||
pEpLog("called"); |
|||
try { |
|||
PyGILState_STATE gil = PyGILState_Ensure(); |
|||
pEpLog("GIL Aquired"); |
|||
bp::object modref = bp::import("pEp"); |
|||
bp::object funcref = modref.attr("notify_handshake"); |
|||
bp::call<void>(funcref.ptr(), me, partner, signal); |
|||
PyGILState_Release(gil); |
|||
pEpLog("GIL released"); |
|||
} catch (exception &e) { |
|||
} |
|||
|
|||
return ::PEP_STATUS_OK; |
|||
} |
|||
|
|||
void start_sync() { |
|||
CallbackDispatcher::start_sync(); |
|||
} |
|||
|
|||
void shutdown_sync() { |
|||
CallbackDispatcher::stop_sync(); |
|||
} |
|||
|
|||
void debug_color(int ansi_color) { |
|||
::set_debug_color(Adapter::session(), ansi_color); |
|||
} |
|||
|
|||
void leave_device_group() { |
|||
::leave_device_group(Adapter::session()); |
|||
} |
|||
|
|||
bool is_sync_active() { |
|||
return Adapter::is_sync_running(); |
|||
} |
|||
|
|||
void testfunc() { |
|||
_messageToSend(nullptr); |
|||
} |
|||
|
|||
void deliverHandshakeResult(int result, bp::object identities) { |
|||
identity_list *shared_identities = nullptr; |
|||
if (identities != bp::api::object() && boost::python::len(identities)) { |
|||
shared_identities = ::new_identity_list(nullptr); |
|||
if (!shared_identities) { |
|||
throw bad_alloc(); |
|||
} |
|||
|
|||
try { |
|||
::identity_list *si = shared_identities; |
|||
for (int i = 0; i < bp::len(identities); ++i) { |
|||
Identity ident = bp::extract<Identity>(identities[i]); |
|||
si = ::identity_list_add(si, ident); |
|||
if (!si) { |
|||
throw bad_alloc(); |
|||
} |
|||
} |
|||
} catch (exception &ex) { |
|||
::free_identity_list(shared_identities); |
|||
throw ex; |
|||
} |
|||
} |
|||
|
|||
::PEP_STATUS status = ::deliverHandshakeResult(Adapter::session(), (::sync_handshake_result)result, shared_identities); |
|||
free_identity_list(shared_identities); |
|||
_throw_status(status); |
|||
} |
|||
} // namespace PythonAdapter
|
|||
} // namespace pEp
|
@ -0,0 +1,84 @@ |
|||
// This file is under GNU Affero General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#ifndef ADAPTER_MAIN_HH |
|||
#define ADAPTER_MAIN_HH |
|||
|
|||
// System
|
|||
#include <string> |
|||
#include <iomanip> |
|||
|
|||
// Boost
|
|||
#include <boost/python.hpp> |
|||
#include <boost/locale.hpp> |
|||
|
|||
// Engine
|
|||
#include <pEp/pEpEngine.h> |
|||
#include <pEp/keymanagement.h> |
|||
#include <pEp/identity_list.h> |
|||
#include <pEp/key_reset.h> |
|||
#include <pEp/sync_api.h> |
|||
#include <pEp/mime.h> |
|||
#include <pEp/message.h> |
|||
#include <pEp/message_api.h> |
|||
#include <pEp/sync_codec.h> |
|||
#include <pEp/distribution_codec.h> |
|||
#include <pEp/timestamp.h> |
|||
#include <pEp/stringpair.h> |
|||
|
|||
// libpEpAdapter
|
|||
#include <pEp/Adapter.hh> |
|||
#include <pEp/callback_dispatcher.hh> |
|||
#include <pEp/status_to_string.hh> |
|||
#include <pEp/pEpLog.hh> |
|||
|
|||
namespace pEp { |
|||
namespace PythonAdapter { |
|||
|
|||
using namespace std; |
|||
namespace bp = boost::python; |
|||
namespace bl = boost::locale; |
|||
|
|||
void init_before_main_module(); |
|||
|
|||
void _init_after_main_module(); |
|||
|
|||
void testfunc(); |
|||
|
|||
|
|||
//extern string device_name;
|
|||
|
|||
string about(); |
|||
|
|||
void config_passive_mode(bool enable); |
|||
|
|||
void start_sync(); |
|||
|
|||
void shutdown_sync(); |
|||
|
|||
void debug_color(int ansi_color); |
|||
|
|||
bool is_sync_active(); |
|||
|
|||
void config_unencrypted_subject(bool enable); |
|||
|
|||
void key_reset_user(const string &user_id, const string &fpr); |
|||
|
|||
void key_reset_user2(const string &user_id); |
|||
|
|||
void key_reset_all_own_keys(); |
|||
|
|||
void _throw_status(::PEP_STATUS status); |
|||
|
|||
void leave_device_group(); |
|||
|
|||
::PEP_STATUS _messageToSend(::message *msg); |
|||
|
|||
::PEP_STATUS notifyHandshake(::pEp_identity *me, ::pEp_identity *partner, ::sync_handshake_signal signal); |
|||
|
|||
void deliverHandshakeResult(int result, bp::object identities); |
|||
|
|||
} // namespace PythonAdapter
|
|||
} // namespace pEp
|
|||
|
|||
#endif // ADAPTER_MAIN_HH
|
@ -1,161 +1,152 @@ |
|||
// This file is under GNU Affero General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
// System
|
|||
#include <sstream> |
|||
|
|||
// Engine
|
|||
#include <pEp/keymanagement.h> |
|||
#include <pEp/message_api.h> |
|||
#include <pEp/Adapter.hh> |
|||
|
|||
// local
|
|||
#include "basic_api.hh" |
|||
|
|||
namespace pEp { |
|||
namespace PythonAdapter { |
|||
using namespace std; |
|||
namespace PythonAdapter { |
|||
|
|||
void update_identity(Identity &ident) { |
|||
if (ident.address() == "") |
|||
void update_identity(Identity &ident) { |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.user_id() == PEP_OWN_USERID) |
|||
throw runtime_error("update_identity: '" |
|||
PEP_OWN_USERID |
|||
"' may only be used for own identities"); |
|||
|
|||
PEP_STATUS status = update_identity(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
if (ident.user_id() == PEP_OWN_USERID) { |
|||
throw runtime_error("update_identity: '" PEP_OWN_USERID "' may only be used for own identities"); |
|||
} |
|||
::PEP_STATUS status = ::update_identity(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
void myself(Identity &ident) { |
|||
if (ident.address() == "") |
|||
void myself(Identity &ident) { |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.username() == "") |
|||
} |
|||
if (ident.username() == "") { |
|||
throw invalid_argument("username needed"); |
|||
|
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
ident.user_id(ident.address()); |
|||
|
|||
PEP_STATUS status = myself(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
::PEP_STATUS status = ::myself(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
string _trustwords(Identity me, Identity partner, string lang, bool full) { |
|||
if (me.fpr() == "" || partner.fpr() == "") |
|||
string _trustwords(Identity me, Identity partner, string lang, bool full) { |
|||
if (me.fpr() == "" || partner.fpr() == "") { |
|||
throw invalid_argument("fingerprint needed in Identities"); |
|||
|
|||
if (lang == "" && me.lang() == partner.lang()) |
|||
} |
|||
if (lang == "" && me.lang() == partner.lang()) { |
|||
lang = me.lang(); |
|||
|
|||
char *words = NULL; |
|||
} |
|||
char *words = nullptr; |
|||
size_t size = 0; |
|||
PEP_STATUS status = get_trustwords(Adapter::session(), me, partner, |
|||
lang.c_str(), &words, &size, full); |
|||
::PEP_STATUS status = ::get_trustwords(Adapter::session(), me, partner, lang.c_str(), &words, &size, full); |
|||
_throw_status(status); |
|||
return words; |
|||
} |
|||
} |
|||
|
|||
void trust_personal_key(Identity ident) { |
|||
if (ident.fpr() == "") |
|||
void trust_personal_key(Identity ident) { |
|||
if (ident.fpr() == "") { |
|||
throw invalid_argument("fingerprint needed in Identities"); |
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
throw invalid_argument("user_id must be provided"); |
|||
|
|||
PEP_STATUS status = trust_personal_key(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
::PEP_STATUS status = ::trust_personal_key(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
void set_identity_flags(Identity ident, identity_flags_t flags) { |
|||
if (ident.address() == "") |
|||
void set_identity_flags(Identity ident,const ::identity_flags_t &flags) { |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
throw invalid_argument("user_id needed"); |
|||
|
|||
PEP_STATUS status = set_identity_flags(Adapter::session(), ident, flags); |
|||
_throw_status(status); |
|||
} |
|||
::PEP_STATUS status = ::set_identity_flags(Adapter::session(), ident, flags); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
void unset_identity_flags(Identity ident, identity_flags_t flags) { |
|||
if (ident.address() == "") |
|||
void unset_identity_flags(Identity ident,const ::identity_flags_t &flags) { |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
throw invalid_argument("user_id needed"); |
|||
|
|||
PEP_STATUS status = unset_identity_flags(Adapter::session(), ident, flags); |
|||
_throw_status(status); |
|||
} |
|||
::PEP_STATUS status = ::unset_identity_flags(Adapter::session(), ident, flags); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
void key_reset_trust(Identity ident) { |
|||
if (ident.fpr() == "") |
|||
void key_reset_trust(Identity ident) { |
|||
if (ident.fpr() == "") { |
|||
throw invalid_argument("fpr needed"); |
|||
if (ident.address() == "") |
|||
} |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
throw invalid_argument("user_id needed"); |
|||
|
|||
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) |
|||
::PEP_STATUS status = ::key_reset_trust(Adapter::session(), ident); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
auto result = boost::python::list(); |
|||
bp::list import_key(const string &key_data) { |
|||
::identity_list *private_keys = nullptr; |
|||
::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 = bp::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); |
|||
::free_identity_list(private_keys); |
|||
throw bad_alloc(); |
|||
} |
|||
result.append(Identity(ident)); |
|||
} |
|||
|
|||
free_identity_list(private_keys); |
|||
::free_identity_list(private_keys); |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
string export_key(Identity ident) { |
|||
PEP_STATUS status = PEP_STATUS_OK; |
|||
char *key_data = NULL; |
|||
string export_key(Identity ident) { |
|||
::PEP_STATUS status = ::PEP_STATUS_OK; |
|||
char *key_data = nullptr; |
|||
size_t size; |
|||
status = ::export_key(Adapter::session(), ident.fpr().c_str(), &key_data, &size); |
|||
|
|||
_throw_status(status); |
|||
return key_data; |
|||
} |
|||
} |
|||
|
|||
string export_secret_key(Identity ident) { |
|||
PEP_STATUS status = PEP_STATUS_OK; |
|||
string export_secret_key(Identity ident) { |
|||
::PEP_STATUS status = ::PEP_STATUS_OK; |
|||
char *key_data = NULL; |
|||
size_t size; |
|||
status = ::export_secret_key(Adapter::session(), ident.fpr().c_str(), &key_data, &size); |
|||
|
|||
_throw_status(status); |
|||
return key_data; |
|||
} |
|||
} |
|||
|
|||
void set_own_key(Identity &ident, string fpr) { |
|||
if (ident.address() == "") |
|||
void set_own_key(Identity &ident, const string &fpr) { |
|||
if (ident.address() == "") { |
|||
throw invalid_argument("address needed"); |
|||
if (ident.username() == "") |
|||
} |
|||
if (ident.username() == "") { |
|||
throw invalid_argument("username needed"); |
|||
if (ident.user_id() == "") |
|||
} |
|||
if (ident.user_id() == "") { |
|||
throw invalid_argument("user_id needed"); |
|||
if (fpr == "") |
|||
} |
|||
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); |
|||
::PEP_STATUS status = ::set_own_key(Adapter::session(), ident, fpr_c); |
|||
_throw_status(status); |
|||
} |
|||
|
|||
} // namespace PythonAdapter
|
|||
} |
|||
} // namespace PythonAdapter
|
|||
} // namespace pEp
|
|||
|
|||
|
|||
|
@ -1,161 +1,158 @@ |
|||
// This file is under GNU Affero General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
// Engine
|
|||
#include <pEp/pEpEngine.h> |
|||
#include <pEp/message_api.h> |
|||
#include <pEp/sync_api.h> |
|||
#include <pEp/sync_codec.h> |
|||
#include <pEp/distribution_codec.h> |
|||
|
|||
// local
|
|||
#include "message_api.hh" |
|||
#include "basic_api.hh" |
|||
|
|||
namespace pEp { |
|||
namespace PythonAdapter { |
|||
using namespace std; |
|||
using namespace boost::python; |
|||
namespace PythonAdapter { |
|||
|
|||
|
|||
Message encrypt_message(Message src, boost::python::list extra, int enc_format, int flags) { |
|||
Message encrypt_message(Message src, bp::list extra, int enc_format, int flags) { |
|||
Identity _from = src.from(); |
|||
if (_from.address() == "") |
|||
if (_from.address() == "") { |
|||
throw invalid_argument("encrypt_message: src.from_.address empty"); |
|||
if (_from.username() == "") |
|||
} |
|||
if (_from.username() == "") { |
|||
throw invalid_argument("encrypt_message: src.from_.username empty"); |
|||
} |
|||
|
|||
if (_from.user_id() == "") |
|||
if (_from.user_id() == "") { |
|||
src.from().user_id(_from.address()); |
|||
} |
|||
|
|||
stringlist_t *_extra = to_stringlist(extra); |
|||
PEP_enc_format _enc_format = (PEP_enc_format) enc_format; |
|||
PEP_encrypt_flags_t _flags = (PEP_encrypt_flags_t) flags; |
|||
message *_dst = NULL; |
|||
::stringlist_t *_extra = to_stringlist(extra); |
|||
::PEP_enc_format _enc_format = (::PEP_enc_format)enc_format; |
|||
::PEP_encrypt_flags_t _flags = (::PEP_encrypt_flags_t)flags; |
|||
::message *_dst = nullptr; |
|||
|
|||
message *_src = src; |
|||
PEP_STATUS status = encrypt_message(Adapter::session(), _src, _extra, &_dst, |
|||
_enc_format, _flags); |
|||
free_stringlist(_extra); |
|||
::message *_src = src; |
|||
::PEP_STATUS status = ::encrypt_message(Adapter::session(), _src, _extra, &_dst, _enc_format, _flags); |
|||
::free_stringlist(_extra); |
|||
_throw_status(status); |
|||
|
|||
if (!_dst || _dst == _src) |
|||
if (!_dst || _dst == _src) { |
|||
return Message(_src); |
|||
} |
|||
|
|||
return Message(_dst); |
|||
} |
|||
} |
|||
|
|||
boost::python::tuple decrypt_message(Message src, int flags) { |
|||
message *_dst = NULL; |
|||
stringlist_t *_keylist = NULL; |
|||
PEP_rating _rating = PEP_rating_undefined; |
|||
PEP_decrypt_flags_t _flags = (PEP_decrypt_flags_t) flags; |
|||
message *_src = src; |
|||
bp::tuple decrypt_message(Message src, int flags) { |
|||
::message *_dst = nullptr; |
|||
::stringlist_t *_keylist = nullptr; |
|||
::PEP_rating _rating = ::PEP_rating_undefined; |
|||
::PEP_decrypt_flags_t _flags = (::PEP_decrypt_flags_t)flags; |
|||
::message *_src = src; |
|||
|
|||
PEP_STATUS status = ::decrypt_message(Adapter::session(), _src, &_dst, &_keylist, |
|||
&_rating, &_flags); |
|||
::PEP_STATUS status = ::decrypt_message(Adapter::session(), _src, &_dst, &_keylist, &_rating, &_flags); |
|||
_throw_status(status); |
|||
|
|||
boost::python::list keylist; |
|||
bp::list keylist; |
|||
if (_keylist) { |
|||
keylist = from_stringlist(_keylist); |
|||
free_stringlist(_keylist); |
|||
::free_stringlist(_keylist); |
|||
} |
|||
|
|||
Message dst = _dst ? Message(_dst) : Message(src); |
|||
return boost::python::make_tuple(dst, keylist, _rating, _flags); |
|||
} |
|||
return bp::make_tuple(dst, keylist, _rating, _flags); |
|||
} |
|||
|
|||
PEP_color _color(int rating) { |
|||
return ::color_from_rating((PEP_rating) rating); |
|||
} |
|||
::PEP_color _color(int rating) { |
|||
return ::color_from_rating((::PEP_rating)rating); |
|||
} |
|||
|
|||
boost::python::tuple sync_decode(object buffer) { |
|||
bp::tuple sync_decode(bp::object buffer) { |
|||
Py_buffer src; |
|||
int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO); |
|||
if (result) |
|||
if (result) { |
|||
throw invalid_argument("need a contiguous buffer to read"); |
|||
} |
|||
|
|||
char *dst = NULL; |
|||
PEP_STATUS status = PER_to_XER_Sync_msg((char *) src.buf, src.len, &dst); |
|||
char *dst = nullptr; |
|||
::PEP_STATUS status = ::PER_to_XER_Sync_msg((char *)src.buf, src.len, &dst); |
|||
PyBuffer_Release(&src); |
|||
_throw_status(status); |
|||
|
|||
string _dst(dst); |
|||
free(dst); |
|||
return boost::python::make_tuple(_dst, 0); |
|||
} |
|||
return bp::make_tuple(_dst, 0); |
|||
} |
|||
|
|||
static boost::python::tuple sync_encode(string text) { |
|||
char *data = NULL; |
|||
static bp::tuple sync_encode(string text) { |
|||
char *data = nullptr; |
|||
size_t size = 0; |
|||
PEP_STATUS status = XER_to_PER_Sync_msg(text.c_str(), &data, &size); |
|||
::PEP_STATUS status = ::XER_to_PER_Sync_msg(text.c_str(), &data, &size); |
|||
_throw_status(status); |
|||
|
|||
PyObject *ba = PyBytes_FromStringAndSize(data, size); |
|||
PyObject * ba = PyBytes_FromStringAndSize(data, size); |
|||
free(data); |
|||
if (!ba) |
|||
if (!ba) { |
|||
throw bad_alloc(); |
|||
|
|||
return boost::python::make_tuple(object(handle<>(ba)), 0); |
|||
} |
|||
|
|||
boost::python::tuple Distribution_decode(object buffer) { |
|||
return bp::make_tuple(bp::object(bp::handle<>(ba)), 0); |
|||
} |
|||
|
|||
bp::tuple Distribution_decode(bp::object buffer) { |
|||
Py_buffer src; |
|||
int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO); |
|||
if (result) |
|||
if (result) { |
|||
throw invalid_argument("need a contiguous buffer to read"); |
|||
} |
|||
|
|||
char *dst = NULL; |
|||
PEP_STATUS status = PER_to_XER_Distribution_msg((char *) src.buf, src.len, &dst); |
|||
char *dst = nullptr; |
|||
::PEP_STATUS status = ::PER_to_XER_Distribution_msg((char *)src.buf, src.len, &dst); |
|||
PyBuffer_Release(&src); |
|||
_throw_status(status); |
|||
|
|||
string _dst(dst); |
|||
free(dst); |
|||
return boost::python::make_tuple(_dst, 0); |
|||
} |
|||
return bp::make_tuple(_dst, 0); |
|||
} |
|||
|
|||
static boost::python::tuple Distribution_encode(string text) { |
|||
char *data = NULL; |
|||
static bp::tuple Distribution_encode(string text) { |
|||
char *data = nullptr; |
|||
size_t size = 0; |
|||
PEP_STATUS status = XER_to_PER_Distribution_msg(text.c_str(), &data, &size); |
|||
::PEP_STATUS status = ::XER_to_PER_Distribution_msg(text.c_str(), &data, &size); |
|||
_throw_status(status); |
|||
|
|||
PyObject *ba = PyBytes_FromStringAndSize(data, size); |
|||
PyObject * ba = PyBytes_FromStringAndSize(data, size); |
|||
free(data); |
|||
if (!ba) |
|||
if (!ba) { |
|||
throw bad_alloc(); |
|||
|
|||
return boost::python::make_tuple(object(handle<>(ba)), 0); |
|||
} |
|||
|
|||
object sync_search(string name) { |
|||
return bp::make_tuple(bp::object(bp::handle<>(ba)), 0); |
|||
} |
|||
|
|||
bp::object sync_search(string name) { |
|||
if (name != "pep.sync") { |
|||
return object(); |
|||
return bp::object(); |
|||
} else { |
|||
object codecs = import("codecs"); |
|||
object CodecInfo = codecs.attr("CodecInfo"); |
|||
bp::object codecs = bp::import("codecs"); |
|||
bp::object CodecInfo = codecs.attr("CodecInfo"); |
|||
|
|||
object _sync_decode = make_function(sync_decode); |
|||
object _sync_encode = make_function(sync_encode); |
|||
bp::object _sync_decode = make_function(sync_decode); |
|||
bp::object _sync_encode = make_function(sync_encode); |
|||
|
|||
return call<object>(CodecInfo.ptr(), _sync_encode, _sync_decode); |
|||
} |
|||
return bp::call<bp::object>(CodecInfo.ptr(), _sync_encode, _sync_decode); |
|||
} |
|||
} |
|||
|
|||
object distribution_search(string name) { |
|||
bp::object distribution_search(string name) { |
|||
if (name != "pep.distribution") { |
|||
return object(); |
|||
return bp::object(); |
|||
} else { |
|||
object codecs = import("codecs"); |
|||
object CodecInfo = codecs.attr("CodecInfo"); |
|||
bp::object codecs = bp::import("codecs"); |
|||
bp::object CodecInfo = codecs.attr("CodecInfo"); |
|||
|
|||
object _distribution_decode = make_function(Distribution_decode); |
|||
object _distribution_encode = make_function(Distribution_encode); |
|||
bp::object _distribution_decode = make_function(Distribution_decode); |
|||
bp::object _distribution_encode = make_function(Distribution_encode); |
|||
|
|||
return call<object>(CodecInfo.ptr(), _distribution_encode, _distribution_decode); |
|||
} |
|||
return bp::call<bp::object>(CodecInfo.ptr(), _distribution_encode, _distribution_decode); |
|||
} |
|||
} |
|||
|
|||
} // namespace PythonAdapter
|
|||
} // namespace pEp {
|
|||
} // namespace PythonAdapter
|
|||
} // namespace pEp
|
|||
|
Loading…
Reference in new issue