From 7ad644c5b987bc0b46a119e8676b97df87d3b386 Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Thu, 21 Nov 2024 18:24:12 +0100 Subject: [PATCH] Fix issue with Testcase in django-pyas2 - test_partner_missing_error as sender may be None. --- pyas2lib/as2.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyas2lib/as2.py b/pyas2lib/as2.py index 2e03331..4b1d0f7 100644 --- a/pyas2lib/as2.py +++ b/pyas2lib/as2.py @@ -918,12 +918,18 @@ def build( ) del signature["MIME-Version"] - signed_data = sign_message( - canonicalize(self.payload), - self.digest_alg, - message.receiver.sign_key, - message.sender.sign_alg, - ) + kwargs = { + "data_to_sign": canonicalize(self.payload), + "digest_alg": self.digest_alg, + "sign_key": message.receiver.sign_key, + } + + # Include the sender sign algo only if sender is provided. + if message.sender: + kwargs["sign_alg"] = message.sender.sign_alg + + signed_data = sign_message(**kwargs) + signature.set_payload(signed_data) encoders.encode_base64(signature)