Skip to content

Commit 7b075af

Browse files
committed
fix: Better API
1 parent b2a47f4 commit 7b075af

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/c2pa/c2pa.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,18 +1276,16 @@ def resource_to_stream(self, uri: str, stream: Any) -> int:
12761276
class Signer:
12771277
"""High-level wrapper for C2PA Signer operations."""
12781278

1279-
def __init__(self, signer_ptr: ctypes.POINTER(C2paSigner), callback_cb: Optional[SignerCallback] = None):
1279+
def __init__(self, signer_ptr: ctypes.POINTER(C2paSigner)):
12801280
"""Initialize a new Signer instance.
12811281
12821282
Note: This constructor is not meant to be called directly.
12831283
Use from_info() or from_callback() instead.
12841284
12851285
Args:
12861286
signer_ptr: Pointer to the C2PA signer
1287-
callback_cb: Optional callback function (for callback-based signers)
12881287
"""
12891288
self._signer = signer_ptr
1290-
self._callback_cb = callback_cb # Keep callback alive to prevent garbage collection
12911289
self._closed = False
12921290
self._error_messages = {
12931291
'closed_error': "Signer is closed",
@@ -1446,7 +1444,14 @@ def wrapped_callback(
14461444
raise C2paError("Failed to create signer")
14471445

14481446
# Create and return the signer instance with the callback
1449-
return cls(signer_ptr, callback_cb)
1447+
signer_instance = cls(signer_ptr)
1448+
1449+
# Keep callback alive on the object to prevent gc of the callback
1450+
# So the callback will live as long as the signer leaves,
1451+
# and there is a 1:1 relationship between signer and callback.
1452+
signer_instance._callback_cb = callback_cb
1453+
1454+
return signer_instance
14501455

14511456
def __enter__(self):
14521457
"""Context manager entry."""

0 commit comments

Comments
 (0)