diff --git a/src/message_api.cc b/src/message_api.cc index 07eca57..0a2e44f 100644 --- a/src/message_api.cc +++ b/src/message_api.cc @@ -83,6 +83,21 @@ namespace pEp { free(dst); return _dst; } + + object sync_encode(string text) + { + char *data = NULL; + size_t size = 0; + PEP_STATUS status = encode_sync_msg(text.c_str(), &data, &size); + _throw_status(status); + + PyObject *ba = PyBytes_FromStringAndSize(data, size); + free(data); + if (!ba) + throw bad_alloc(); + + return object(handle<>(ba)); + } #endif } } diff --git a/src/message_api.hh b/src/message_api.hh index fc8fa27..2b93719 100644 --- a/src/message_api.hh +++ b/src/message_api.hh @@ -11,6 +11,7 @@ namespace pEp { #ifndef NDEBUG void _config_keep_sync_msg(bool enabled); string sync_decode(object buffer); + object sync_encode(string text); #endif } } diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index d7fe418..73b0e4b 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -206,7 +206,8 @@ BOOST_PYTHON_MODULE(pEp) def("trustwords", &_trustwords, "calculate trustwords for two Identities"); #ifndef NDEBUG def("config_keep_sync_msg", &_config_keep_sync_msg, "configure if sync messages are being kept or not"); - def("sync_decode", &sync_decode, "decode sync message to XER/XML"); + def("sync_decode", &sync_decode, "decode sync message to XER/XML text"); + def("sync_encode", &sync_encode, "encode sync message from XER/XML text"); #endif // key sync API