Skip to content

Commit 2bb9697

Browse files
author
Tania Mathern
committed
fix:signfile
1 parent ddd2b6d commit 2bb9697

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/c2pa/c2pa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3749,7 +3749,7 @@ def sign_file(
37493749
if signer is not None:
37503750
return self.sign(signer, mime_type, source_file, dest_file)
37513751
# else:
3752-
return self.sign(mime_type, source_file, dest_file)
3752+
return self.sign_with_context(mime_type, source_file, dest_file)
37533753
except Exception as e:
37543754
raise C2paError(f"Error signing file: {str(e)}") from e
37553755

tests/test_unit_tests.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5606,6 +5606,42 @@ def test_contextual_builder_sign_no_signer_raises(self):
56065606
builder.close()
56075607
context.close()
56085608

5609+
def test_sign_file_with_context_signer_no_explicit_signer(self):
5610+
signer = self._ctx_make_signer()
5611+
context = Context(signer=signer)
5612+
builder = Builder(
5613+
self.test_manifest, context=context,
5614+
)
5615+
with tempfile.TemporaryDirectory() as temp_dir:
5616+
dest_path = os.path.join(temp_dir, "out.jpg")
5617+
manifest_bytes = builder.sign_file(
5618+
source_path=DEFAULT_TEST_FILE,
5619+
dest_path=dest_path,
5620+
)
5621+
self.assertIsNotNone(manifest_bytes)
5622+
self.assertGreater(len(manifest_bytes), 0)
5623+
reader = Reader(dest_path)
5624+
data = reader.json()
5625+
self.assertIsNotNone(data)
5626+
reader.close()
5627+
builder.close()
5628+
context.close()
5629+
5630+
def test_sign_file_no_signer_raises(self):
5631+
context = Context()
5632+
builder = Builder(
5633+
self.test_manifest, context=context,
5634+
)
5635+
with tempfile.TemporaryDirectory() as temp_dir:
5636+
dest_path = os.path.join(temp_dir, "out.jpg")
5637+
with self.assertRaises(Error):
5638+
builder.sign_file(
5639+
source_path=DEFAULT_TEST_FILE,
5640+
dest_path=dest_path,
5641+
)
5642+
builder.close()
5643+
context.close()
5644+
56095645

56105646
class TestContextIntegration(TestContextAPIs):
56115647

0 commit comments

Comments
 (0)