Compare commits

...

2 Commits

Author SHA1 Message Date
Luca Saiu b41ca61b91 change the Python API to follow the engine API after ENGINE-959 4 years ago
Luca Saiu 915f6d0001 adapt to ENGINE-959, without changing the Python side of the API 4 years ago
  1. 4
      examples/simple_xml_msgformat.py
  2. 4
      src/pEp/_pEp/message.hh
  3. 6
      src/pEp/_pEp/message_api.cc
  4. 6
      src/pEp/_pEp/pEpmodule.cc
  5. 2
      test/codec_doctest.py
  6. 4
      test/pyadpt-81.py
  7. 4
      test/sync_handshake.py
  8. 8
      tests/test_basic.py
  9. 8
      tests/test_message.py
  10. 2
      utils/pEp

4
examples/simple_xml_msgformat.py

@ -127,5 +127,5 @@ def parse_serialized_message(transport_message):
pEp_attachs.append(
pEp.Blob(attach.text.encode(), TAG2CT[tagname]))
msg1.attachments = pEp_attachs
msg2, keys, rating, flags = msg1.decrypt()
return msg2, rating
msg2, keys, flags = msg1.decrypt()
return msg2, msg2.rating

4
src/pEp/_pEp/message.hh

@ -169,6 +169,10 @@ namespace pEp {
void enc_format(PEP_enc_format value) { _msg->enc_format = value; }
PEP_rating rating() { return _msg->rating; }
void rating(PEP_rating value) { _msg->rating = value; }
Message encrypt();
Message _encrypt(boost::python::list extra, int enc_format = 4, int flags = 0);

6
src/pEp/_pEp/message_api.cc

@ -47,12 +47,11 @@ namespace pEp {
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;
PEP_STATUS status = ::decrypt_message(Adapter::session(), _src, &_dst, &_keylist,
&_rating, &_flags);
&_flags);
_throw_status(status);
boost::python::list keylist;
@ -62,7 +61,8 @@ namespace pEp {
}
Message dst = _dst ? Message(_dst) : Message(src);
return boost::python::make_tuple(dst, keylist, _rating, _flags);
PEP_rating _rating = dst.rating ();
return boost::python::make_tuple(dst, keylist, _flags);
}
PEP_color _color(int rating) {

6
src/pEp/_pEp/pEpmodule.cc

@ -488,6 +488,11 @@ namespace pEp {
(void(Message::*)(int))
(void(Message::*)(PEP_enc_format)) &Message::enc_format,
"0: unencrypted, 1: inline PGP, 2: S/MIME, 3: PGP/MIME, 4: p≡p format")
.add_property("rating", (int(Message::*)())
(PEP_rating(Message::*)()) &Message::rating,
(void(Message::*)(int))
(void(Message::*)(PEP_rating)) &Message::rating,
"the message rating as computed on this endpoint")
.def("encrypt", (Message(Message::*)())&Message::encrypt)
.def("encrypt", (Message(Message::*)(boost::python::list))&Message::_encrypt)
.def("encrypt", (Message(Message::*)(boost::python::list, int))&Message::_encrypt)
@ -509,7 +514,6 @@ namespace pEp {
"\n"
" msg the decrypted p≡p message\n"
" keys a list of keys being used\n"
" rating the rating of the message as integer\n"
" flags flags set while decryption\n"
)
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")

2
test/codec_doctest.py

@ -4,7 +4,7 @@
"""
>>> import pEp
>>> def message_to_send(msg):
... m, keys, rating, flags = msg.decrypt()
... m, keys, flags = msg.decrypt()
... try:
... m.attachments[0].decode()
... print("decode successfull")

4
test/pyadpt-81.py

@ -6,7 +6,7 @@ import time
def message_to_send(msg):
print("User defined message_to_send() called")
m, keys, rating, flags = msg.decrypt()
m, keys, flags = msg.decrypt()
try:
print(m.attachments[0].decode())
except UnicodeDecodeError as e:
@ -44,4 +44,4 @@ start_stop_sync(1)
# print("is_sync_active: {}".format(pEp.is_sync_active()))
# time.sleep(3)
# pEp.key_reset_all_own_keys()
# time.sleep(3)
# time.sleep(3)

4
test/sync_handshake.py

@ -103,7 +103,7 @@ def messageImapToSend(msg):
def add_debug_info(msg):
if msg.enc_format:
m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC)
m, keys, flags = msg.decrypt(DONT_TRIGGER_SYNC)
else:
m = msg
try:
@ -212,7 +212,7 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
msg = pEp.Message(m)
output("*** Reading")
print_msg(msg)
msg2, keys, rating, flags = msg.decrypt()
msg2, keys, flags = msg.decrypt()
except KeyboardInterrupt:
shutdown_sync()

8
tests/test_basic.py

@ -20,8 +20,8 @@ import pytest
# >>> m.longmsg = "Please call me back"
# >>> m2 = m.encrypt()
# >>> print(m2)
# >>> m3, keys, rating, flags = m2.decrypt()
# >>> rating
# >>> m3, keys, flags = m2.decrypt()
# >>> m3.rating
# pEp.rating.reliable
# """
#
@ -50,6 +50,6 @@ def test_basic(pEp, model):
m.longmsg = constants.BODY
#TODO: encrypt needs to return message type
m2 = m.encrypt()
m3, keys, rating, flags = m2.decrypt()
m3, keys, flags = m2.decrypt()
#TODO: fix pEp.rating
# assert rating == pEp.
# assert m3.rating == pEp.

8
tests/test_message.py

@ -35,13 +35,13 @@ def test_msg_enc_dec_roundtrip(pEp, model, import_ident_alice_as_own_ident, impo
assert enc_msg.longmsg == "this message was encrypted with p≡p https://pEp-project.org"
# Decrypt message.
dec_msg, key_list, rating, r = enc_msg.decrypt()
dec_msg, key_list, r = enc_msg.decrypt()
assert r == 0
# pEp version 2.2 throws this error:
# AttributeError: module 'pEp' has no attribute 'PEP_rating'
# assert rating == pEp.PEP_rating.PEP_rating_reliable
# assert dec_msg.rating == pEp.PEP_rating.PEP_rating_reliable
# It seems to have changed to the following.
assert rating == pEp._pEp.rating.reliable
assert dec_msg.rating == pEp._pEp.rating.reliable
# The first 2 keys are Alice's ones, the last is Bob's one.
assert key_list[0] == key_list[1] == model.alice.fpr
@ -123,7 +123,7 @@ def test_dec_msg_len(pEp, import_ident_alice_as_own_ident, import_ident_bob):
enc_msg = msg.encrypt()
# Decrypt message.
dec_msg, _key_list, _rating, _r = enc_msg.decrypt()
dec_msg, _key_list, _r = enc_msg.decrypt()
dec_msg_len = len(str(dec_msg))
assert dec_msg.longmsg.replace("\r", "") == constants.BODY # msg.longmsg

2
utils/pEp

@ -77,7 +77,7 @@ try:
dst = src.encrypt()
else:
src.dir = 0
dst, keys, rating, flags = src.decrypt()
dst, keys, flags = src.decrypt()
print(str(dst))

Loading…
Cancel
Save