@@ -123,6 +123,19 @@ class C2paSigningAlg(enum.IntEnum):
123
123
ED25519 = 6
124
124
125
125
126
+ # Mapping from C2paSigningAlg enum to string representation,
127
+ # as the enum value currently maps by default to an integer value.
128
+ _ALG_TO_STRING_BYTES_MAPPING = {
129
+ C2paSigningAlg .ES256 : b"es256" ,
130
+ C2paSigningAlg .ES384 : b"es384" ,
131
+ C2paSigningAlg .ES512 : b"es512" ,
132
+ C2paSigningAlg .PS256 : b"ps256" ,
133
+ C2paSigningAlg .PS384 : b"ps384" ,
134
+ C2paSigningAlg .PS512 : b"ps512" ,
135
+ C2paSigningAlg .ED25519 : b"ed25519" ,
136
+ }
137
+
138
+
126
139
# Define callback types
127
140
ReadCallback = ctypes .CFUNCTYPE (
128
141
ctypes .c_ssize_t ,
@@ -205,6 +218,45 @@ class C2paSignerInfo(ctypes.Structure):
205
218
("ta_url" , ctypes .c_char_p ),
206
219
]
207
220
221
+ def __init__ (self , alg , sign_cert , private_key , ta_url ):
222
+ """Initialize C2paSignerInfo with optional parameters.
223
+
224
+ Args:
225
+ alg: The signing algorithm, either as a C2paSigningAlg enum or string or bytes
226
+ (will be converted accordingly to bytes for native library use)
227
+ sign_cert: The signing certificate as a string
228
+ private_key: The private key as a string
229
+ ta_url: The timestamp authority URL as bytes
230
+ """
231
+ # Handle alg parameter: can be C2paSigningAlg enum or string (or bytes), convert as needed
232
+ if isinstance (alg , C2paSigningAlg ):
233
+ # Convert enum to string representation
234
+ alg_str = _ALG_TO_STRING_BYTES_MAPPING .get (alg )
235
+ if alg_str is None :
236
+ raise ValueError (f"Unsupported signing algorithm: { alg } " )
237
+ alg = alg_str
238
+ elif isinstance (alg , str ):
239
+ # String to bytes, as requested by native lib
240
+ alg = alg .encode ('utf-8' )
241
+ elif isinstance (alg , bytes ):
242
+ # In bytes already
243
+ pass
244
+ else :
245
+ raise TypeError (f"alg must be C2paSigningAlg enum, string, or bytes, got { type (alg )} " )
246
+
247
+ # Handle ta_url parameter: allow string or bytes, convert string to bytes as needed
248
+ if isinstance (ta_url , str ):
249
+ # String to bytes, as requested by native lib
250
+ ta_url = ta_url .encode ('utf-8' )
251
+ elif isinstance (ta_url , bytes ):
252
+ # In bytes already
253
+ pass
254
+ else :
255
+ raise TypeError (f"ta_url must be string or bytes, got { type (ta_url )} " )
256
+
257
+ # Call parent constructor with processed values
258
+ super ().__init__ (alg , sign_cert , private_key , ta_url )
259
+
208
260
209
261
class C2paReader (ctypes .Structure ):
210
262
"""Opaque structure for reader context."""
0 commit comments