@@ -135,6 +135,19 @@ class C2paSigningAlg(enum.IntEnum):
135135 ED25519 = 6
136136
137137
138+ # Mapping from C2paSigningAlg enum to string representation,
139+ # as the enum value currently maps by default to an integer value.
140+ _ALG_TO_STRING_BYTES_MAPPING = {
141+ C2paSigningAlg .ES256 : b"es256" ,
142+ C2paSigningAlg .ES384 : b"es384" ,
143+ C2paSigningAlg .ES512 : b"es512" ,
144+ C2paSigningAlg .PS256 : b"ps256" ,
145+ C2paSigningAlg .PS384 : b"ps384" ,
146+ C2paSigningAlg .PS512 : b"ps512" ,
147+ C2paSigningAlg .ED25519 : b"ed25519" ,
148+ }
149+
150+
138151# Define callback types
139152ReadCallback = ctypes .CFUNCTYPE (
140153 ctypes .c_ssize_t ,
@@ -218,6 +231,45 @@ class C2paSignerInfo(ctypes.Structure):
218231 ("ta_url" , ctypes .c_char_p ),
219232 ]
220233
234+ def __init__ (self , alg , sign_cert , private_key , ta_url ):
235+ """Initialize C2paSignerInfo with optional parameters.
236+
237+ Args:
238+ alg: The signing algorithm, either as a C2paSigningAlg enum or string or bytes
239+ (will be converted accordingly to bytes for native library use)
240+ sign_cert: The signing certificate as a string
241+ private_key: The private key as a string
242+ ta_url: The timestamp authority URL as bytes
243+ """
244+ # Handle alg parameter: can be C2paSigningAlg enum or string (or bytes), convert as needed
245+ if isinstance (alg , C2paSigningAlg ):
246+ # Convert enum to string representation
247+ alg_str = _ALG_TO_STRING_BYTES_MAPPING .get (alg )
248+ if alg_str is None :
249+ raise ValueError (f"Unsupported signing algorithm: { alg } " )
250+ alg = alg_str
251+ elif isinstance (alg , str ):
252+ # String to bytes, as requested by native lib
253+ alg = alg .encode ('utf-8' )
254+ elif isinstance (alg , bytes ):
255+ # In bytes already
256+ pass
257+ else :
258+ raise TypeError (f"alg must be C2paSigningAlg enum, string, or bytes, got { type (alg )} " )
259+
260+ # Handle ta_url parameter: allow string or bytes, convert string to bytes as needed
261+ if isinstance (ta_url , str ):
262+ # String to bytes, as requested by native lib
263+ ta_url = ta_url .encode ('utf-8' )
264+ elif isinstance (ta_url , bytes ):
265+ # In bytes already
266+ pass
267+ else :
268+ raise TypeError (f"ta_url must be string or bytes, got { type (ta_url )} " )
269+
270+ # Call parent constructor with processed values
271+ super ().__init__ (alg , sign_cert , private_key , ta_url )
272+
221273
222274class C2paReader (ctypes .Structure ):
223275 """Opaque structure for reader context."""
@@ -2105,7 +2157,7 @@ def _sign_internal(
21052157 dest_stream: The destination stream, as Stream(BytesIO)
21062158
21072159 Returns:
2108- A tuple of (size of C2PA data, manifest bytes)
2160+ Manifest bytes
21092161
21102162 Raises:
21112163 C2paError: If there was an error during signing
0 commit comments