Skip to content

Commit

Permalink
Dont replace "\n" newlines in application/octet-stream payload with "…
Browse files Browse the repository at this point in the history
…\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.
  • Loading branch information
Fabian Brosig committed May 11, 2020
1 parent b86dec3 commit 1beb1ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pyas2lib/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions pyas2lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1beb1ed

Please sign in to comment.