@@ -936,12 +936,13 @@ def sign_callback(data: bytes) -> bytes:
936936 tsa_url = "http://timestamp.digicert.com"
937937 )
938938
939- # Use the overloaded sign_file function with a Signer object
939+ # Test with return_manifest_as_bytes=False (default) - should return JSON string
940940 result_json = sign_file (
941941 self .testPath ,
942942 output_path ,
943943 self .manifestDefinition ,
944- signer
944+ signer ,
945+ False
945946 )
946947
947948 # Verify the output file was created
@@ -956,6 +957,23 @@ def sign_callback(data: bytes) -> bytes:
956957 self .assertIn ("manifests" , manifest_data )
957958 self .assertIn ("active_manifest" , manifest_data )
958959
960+ # Test with return_manifest_as_bytes=True - should return bytes
961+ output_path_bytes = os .path .join (temp_dir , "signed_output_callback_bytes.jpg" )
962+ result_bytes = sign_file (
963+ self .testPath ,
964+ output_path_bytes ,
965+ self .manifestDefinition ,
966+ signer ,
967+ True
968+ )
969+
970+ # Verify the output file was created
971+ self .assertTrue (os .path .exists (output_path_bytes ))
972+
973+ # Verify the result is bytes (not JSON string)
974+ self .assertIsInstance (result_bytes , bytes )
975+ self .assertGreater (len (result_bytes ), 0 )
976+
959977 # Read the signed file and verify the manifest contains expected content
960978 with open (output_path , "rb" ) as file :
961979 reader = Reader ("image/jpeg" , file )
@@ -989,35 +1007,63 @@ def test_sign_file_overloads(self):
9891007 ta_url = b"http://timestamp.digicert.com"
9901008 )
9911009
992- # Test with C2paSignerInfo parameter
1010+ # Test with C2paSignerInfo parameter - JSON return
9931011 result_1 = sign_file (
9941012 self .testPath ,
9951013 output_path_1 ,
9961014 self .manifestDefinition ,
997- signer_info
1015+ signer_info ,
1016+ False
9981017 )
9991018
10001019 self .assertIsInstance (result_1 , str )
10011020 self .assertTrue (os .path .exists (output_path_1 ))
10021021
1022+ # Test with C2paSignerInfo parameter - bytes return
1023+ output_path_1_bytes = os .path .join (temp_dir , "signed_output_1_bytes.jpg" )
1024+ result_1_bytes = sign_file (
1025+ self .testPath ,
1026+ output_path_1_bytes ,
1027+ self .manifestDefinition ,
1028+ signer_info ,
1029+ True
1030+ )
1031+
1032+ self .assertIsInstance (result_1_bytes , bytes )
1033+ self .assertTrue (os .path .exists (output_path_1_bytes ))
1034+
10031035 # Test with Signer object
10041036 output_path_2 = os .path .join (temp_dir , "signed_output_2.jpg" )
10051037
10061038 # Create a signer from the signer info
10071039 signer = Signer .from_info (signer_info )
10081040
1009- # Test with Signer parameter
1041+ # Test with Signer parameter - JSON return
10101042 result_2 = sign_file (
10111043 self .testPath ,
10121044 output_path_2 ,
10131045 self .manifestDefinition ,
1014- signer
1046+ signer ,
1047+ False
10151048 )
10161049
10171050 self .assertIsInstance (result_2 , str )
10181051 self .assertTrue (os .path .exists (output_path_2 ))
1052+
1053+ # Test with Signer parameter - bytes return
1054+ output_path_2_bytes = os .path .join (temp_dir , "signed_output_2_bytes.jpg" )
1055+ result_2_bytes = sign_file (
1056+ self .testPath ,
1057+ output_path_2_bytes ,
1058+ self .manifestDefinition ,
1059+ signer ,
1060+ True
1061+ )
10191062
1020- # Both results should be similar (same manifest structure)
1063+ self .assertIsInstance (result_2_bytes , bytes )
1064+ self .assertTrue (os .path .exists (output_path_2_bytes ))
1065+
1066+ # Both JSON results should be similar (same manifest structure)
10211067 manifest_1 = json .loads (result_1 )
10221068 manifest_2 = json .loads (result_2 )
10231069
@@ -1026,6 +1072,10 @@ def test_sign_file_overloads(self):
10261072 self .assertIn ("active_manifest" , manifest_1 )
10271073 self .assertIn ("active_manifest" , manifest_2 )
10281074
1075+ # Both bytes results should be non-empty
1076+ self .assertGreater (len (result_1_bytes ), 0 )
1077+ self .assertGreater (len (result_2_bytes ), 0 )
1078+
10291079 finally :
10301080 # Clean up the temporary directory
10311081 shutil .rmtree (temp_dir )
0 commit comments