-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyas2lib.Message.build should force binary encoding for the encrypted payload. #20
Comments
it looks like Django AS2 has no support for binary file types... so my previous suggestion is wrong. I ended up with this fix. Add Then in as2lib utils class BinaryBytesGenerator(BytesGenerator):
"""Override the bytes generator to better handle binary data."""
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",
'octet-stream',
]:
payload = msg.get_payload(decode=True)
if payload is None:
return
else:
self._fp.write(payload)
else:
super()._handle_text(msg)
_writeBody = _handle_text and in as2lib as2 Message.build I have
|
Makes sense @adiroiban can you open a PR with these changes? |
I will look into this. It looks like For my tests, I was using the released version. I am now trying to understand the code and write automated tests. Will create a PR soon. |
PR at #21 we can move the discussion there. Will open a separate PR for Django |
If I am sending an image (.JPG) with Django-AS2 as unsigned encrypted file pyas2lib will always transfer it as text file.. that is replace unix newline with network newline.
I am not sure where this should be fixed.
I would say that pyas2lib.utils.BinaryBytesGenerator should never try to replace unix newlines.
Right now, the implementation will handle binary only if Content-Transfer-Encoding is binary and only for a certain subtype.
build
method on the Message has thecontent_type
argument, which can be used to force the payload but it has no way to set the Content-Transfer-Encoding header on the payload.My suggestion is to have something line this in utils:
The text was updated successfully, but these errors were encountered: