From 1beb1ed468ccb828ccf24bcc19a549a40eebaf10 Mon Sep 17 00:00:00 2001 From: Fabian Brosig Date: Mon, 11 May 2020 17:01:47 +0200 Subject: [PATCH] Dont replace "\n" newlines in application/octet-stream payload with "\r\n" When building an AS/2 message with data of content-type "application/octet-stream", the payload's "\n" newlines got replaced with "\r\n", leading to corrupted message payloads. --- pyas2lib/tests/test_advanced.py | 3 +-- pyas2lib/utils.py | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pyas2lib/tests/test_advanced.py b/pyas2lib/tests/test_advanced.py index 5179513..10f83d1 100644 --- a/pyas2lib/tests/test_advanced.py +++ b/pyas2lib/tests/test_advanced.py @@ -52,9 +52,8 @@ def test_binary_message(self): ) # Compare the mic contents of the input and output messages - # self.assertEqual(original_message, - # in_message.payload.get_payload(decode=True)) self.assertEqual(status, "processed") + self.assertEqual(original_message, in_message.payload.get_payload(decode=True)) self.assertTrue(in_message.signed) self.assertTrue(in_message.encrypted) self.assertEqual(out_message.mic, in_message.mic) diff --git a/pyas2lib/utils.py b/pyas2lib/utils.py index f50f5c3..200294c 100644 --- a/pyas2lib/utils.py +++ b/pyas2lib/utils.py @@ -45,12 +45,10 @@ def _handle_text(self, msg): Handle writing the binary messages to prevent default behaviour of newline replacements. """ - if msg.get( - "Content-Transfer-Encoding" - ) == "binary" and msg.get_content_subtype() in [ - "pkcs7-mime", - "pkcs7-signature", - ]: + if msg.get_content_type() == "application/octet-stream" or ( + msg.get("Content-Transfer-Encoding") == "binary" + and msg.get_content_subtype() in ["pkcs7-mime", "pkcs7-signature",] + ): payload = msg.get_payload(decode=True) if payload is None: return