Skip to content

Commit 6e9cd77

Browse files
committed
ci: Merge branch 'mathern/sign-file' into mathern/add-extension-guessing
2 parents 376a562 + a8b5904 commit 6e9cd77

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

src/c2pa/c2pa.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def sign_file(
761761

762762
# Use the builder's internal signing logic to get manifest
763763
# bytes
764-
result, manifest_bytes = builder._sign_internal(
764+
manifest_bytes = builder._sign_internal(
765765
signer, mime_type, source_stream, dest_stream)
766766

767767
return manifest_bytes
@@ -1975,7 +1975,7 @@ def _sign_internal(
19751975
# Ignore errors during cleanup
19761976
pass
19771977

1978-
return result, manifest_bytes
1978+
return manifest_bytes
19791979
finally:
19801980
# Ensure both streams are cleaned up
19811981
source_stream.close()
@@ -2043,9 +2043,8 @@ def sign_file(self,
20432043
dest_stream = Stream(dest_file)
20442044

20452045
# Use the internal stream-base signing logic
2046-
result, manifest_bytes = self._sign_internal(
2046+
return self._sign_internal(
20472047
signer, mime_type, source_stream, dest_stream)
2048-
return result, manifest_bytes
20492048

20502049

20512050
def format_embeddable(format: str, manifest_bytes: bytes) -> tuple[int, bytes]:

tests/test_unit_tests.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_remote_sign_using_returned_bytes(self):
359359
builder = Builder(self.manifestDefinition)
360360
builder.set_no_embed()
361361
with io.BytesIO() as output_buffer:
362-
_, manifest_data = builder.sign(
362+
manifest_data = builder.sign(
363363
self.signer, "image/jpeg", file, output_buffer)
364364
output_buffer.seek(0)
365365
read_buffer = io.BytesIO(output_buffer.getvalue())
@@ -732,7 +732,7 @@ def test_builder_set_remote_url(self):
732732
builder.sign(self.signer, "image/jpeg", file, output)
733733
output.seek(0)
734734
d = output.read()
735-
self.assertIn(b'provenance="http://this_does_not_exist/foo.jpg"', d)
735+
self.assertIn(b'provenance="http://this_does_not_exist/foo.jpg"', d)
736736

737737
def test_builder_set_remote_url_no_embed(self):
738738
"""Test setting the remote url of a builder with no embed flag."""
@@ -763,7 +763,7 @@ def test_sign_file(self):
763763

764764
# Use the sign_file method
765765
builder = Builder(self.manifestDefinition)
766-
result, manifest_bytes = builder.sign_file(
766+
manifest_bytes = builder.sign_file(
767767
source_path=self.testPath,
768768
dest_path=output_path,
769769
signer=self.signer
@@ -772,11 +772,6 @@ def test_sign_file(self):
772772
# Verify the output file was created
773773
self.assertTrue(os.path.exists(output_path))
774774

775-
# Verify we got both result and manifest bytes
776-
self.assertIsInstance(result, int)
777-
self.assertIsInstance(manifest_bytes, bytes)
778-
self.assertGreater(len(manifest_bytes), 0)
779-
780775
# Read the signed file and verify the manifest
781776
with open(output_path, "rb") as file:
782777
reader = Reader("image/jpeg", file)
@@ -953,7 +948,7 @@ def test_sign_file_callback_signer(self):
953948
tsa_url="http://timestamp.digicert.com"
954949
)
955950

956-
result, manifest_bytes = builder.sign_file(
951+
manifest_bytes = builder.sign_file(
957952
source_path=self.testPath,
958953
dest_path=output_path,
959954
signer=signer
@@ -963,7 +958,6 @@ def test_sign_file_callback_signer(self):
963958
self.assertTrue(os.path.exists(output_path))
964959

965960
# Verify results
966-
self.assertIsInstance(result, int)
967961
self.assertIsInstance(manifest_bytes, bytes)
968962
self.assertGreater(len(manifest_bytes), 0)
969963

@@ -1001,15 +995,14 @@ def test_sign_file_callback_signer_managed(self):
1001995
) as signer:
1002996

1003997
# Sign the file
1004-
result, manifest_bytes = builder.sign_file(
998+
manifest_bytes = builder.sign_file(
1005999
source_path=self.testPath,
10061000
dest_path=output_path,
10071001
signer=signer
10081002
)
10091003

10101004
# Verify results
10111005
self.assertTrue(os.path.exists(output_path))
1012-
self.assertIsInstance(result, int)
10131006
self.assertIsInstance(manifest_bytes, bytes)
10141007
self.assertGreater(len(manifest_bytes), 0)
10151008

@@ -1048,30 +1041,28 @@ def test_sign_file_callback_signer_managed_multiple_uses(self):
10481041

10491042
# First signing operation
10501043
output_path_1 = os.path.join(temp_dir, "signed_output_1.jpg")
1051-
result_1, manifest_bytes_1 = builder.sign_file(
1044+
manifest_bytes_1 = builder.sign_file(
10521045
source_path=self.testPath,
10531046
dest_path=output_path_1,
10541047
signer=signer
10551048
)
10561049

10571050
# Verify first signing was successful
10581051
self.assertTrue(os.path.exists(output_path_1))
1059-
self.assertIsInstance(result_1, int)
10601052
self.assertIsInstance(manifest_bytes_1, bytes)
10611053
self.assertGreater(len(manifest_bytes_1), 0)
10621054

10631055
# Second signing operation with the same signer
10641056
# This is to verify we don't free the signer or the callback too early
10651057
output_path_2 = os.path.join(temp_dir, "signed_output_2.jpg")
1066-
result_2, manifest_bytes_2 = builder.sign_file(
1058+
manifest_bytes_2 = builder.sign_file(
10671059
source_path=self.testPath,
10681060
dest_path=output_path_2,
10691061
signer=signer
10701062
)
10711063

10721064
# Verify second signing was successful
10731065
self.assertTrue(os.path.exists(output_path_2))
1074-
self.assertIsInstance(result_2, int)
10751066
self.assertIsInstance(manifest_bytes_2, bytes)
10761067
self.assertGreater(len(manifest_bytes_2), 0)
10771068

@@ -1114,7 +1105,7 @@ def test_builder_sign_file_callback_signer_from_callback(self):
11141105
tsa_url="http://timestamp.digicert.com"
11151106
)
11161107

1117-
result, manifest_bytes = builder.sign_file(
1108+
manifest_bytes = builder.sign_file(
11181109
source_path=self.testPath,
11191110
dest_path=output_path,
11201111
signer=signer
@@ -1124,7 +1115,6 @@ def test_builder_sign_file_callback_signer_from_callback(self):
11241115
self.assertTrue(os.path.exists(output_path))
11251116

11261117
# Verify results
1127-
self.assertIsInstance(result, int)
11281118
self.assertIsInstance(manifest_bytes, bytes)
11291119
self.assertGreater(len(manifest_bytes), 0)
11301120

@@ -1333,7 +1323,7 @@ def error_callback_signer(data: bytes) -> bytes:
13331323

13341324
# The signing operation should fail due to the error callback
13351325
with self.assertRaises(Error):
1336-
result, manifest_bytes = builder.sign_file(
1326+
builder.sign_file(
13371327
source_path=self.testPath,
13381328
dest_path=output_path,
13391329
signer=signer

0 commit comments

Comments
 (0)