1
1
import ctypes
2
+ from collections .abc import Sequence
3
+ from typing import Any
2
4
3
5
from lxml .etree import _Element
4
6
@@ -37,7 +39,7 @@ def add_encrypted_key(
37
39
c_recipient = ctypes .c_char_p (recipient .encode ('utf-8' ) if recipient else None )
38
40
39
41
# Call the C function
40
- result = libxmlsec .PyXmlSec_TemplateAddEncryptedKey (node , method , c_id , c_type , c_recipient )
42
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddEncryptedKey (node , method , c_id , c_type , c_recipient )
41
43
42
44
if not result :
43
45
raise RuntimeError ('Failed to add encrypted key' )
@@ -54,7 +56,7 @@ def add_key_name(node: _Element, name: str | None = None) -> _Element:
54
56
:return: The modified XML node.
55
57
"""
56
58
c_name = ctypes .c_char_p (name .encode ('utf-8' ) if name else None )
57
- result = libxmlsec .PyXmlSec_TemplateAddKeyName (node , c_name )
59
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddKeyName (node , c_name )
58
60
59
61
if not result :
60
62
raise RuntimeError ('Failed to add key name' )
@@ -69,7 +71,7 @@ def add_key_value(node: _Element) -> _Element:
69
71
:param node: The XML node to which the key value will be added.
70
72
:return: The modified XML node.
71
73
"""
72
- result = libxmlsec .PyXmlSec_TemplateAddKeyValue (node )
74
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddKeyValue (node )
73
75
74
76
if not result :
75
77
raise RuntimeError ('Failed to add key value' )
@@ -94,7 +96,7 @@ def add_reference(
94
96
c_uri = ctypes .c_char_p (uri .encode ('utf-8' ) if uri else None )
95
97
c_type = ctypes .c_char_p (type .encode ('utf-8' ) if type else None )
96
98
97
- result = libxmlsec .PyXmlSec_TemplateAddReference (node , digest_method , c_id , c_uri , c_type )
99
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddReference (node , digest_method , c_id , c_uri , c_type )
98
100
99
101
if not result :
100
102
raise RuntimeError ('Failed to add reference' )
@@ -110,7 +112,7 @@ def add_transform(node: _Element, transform: Transform) -> Any:
110
112
:param transform: The transform to add.
111
113
:return: The modified XML node.
112
114
"""
113
- result = libxmlsec .PyXmlSec_TemplateAddTransform (node , transform )
115
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddTransform (node , transform )
114
116
115
117
if not result :
116
118
raise RuntimeError ('Failed to add transform' )
@@ -125,7 +127,7 @@ def add_x509_data(node: _Element) -> _Element:
125
127
:param node: The XML node to which the X509 data will be added.
126
128
:return: The modified XML node.
127
129
"""
128
- result = libxmlsec .PyXmlSec_TemplateAddX509Data (node )
130
+ result : _Element = libxmlsec .PyXmlSec_TemplateAddX509Data (node )
129
131
130
132
if not result :
131
133
raise RuntimeError ('Failed to add X509 data' )
@@ -142,7 +144,7 @@ def create(node: _Element, c14n_method: Transform, sign_method: Transform) -> _E
142
144
:param sign_method: The signature method.
143
145
:return: The created XML node.
144
146
"""
145
- result = libxmlsec .PyXmlSec_TemplateCreate (node , c14n_method , sign_method )
147
+ result : _Element = libxmlsec .PyXmlSec_TemplateCreate (node , c14n_method , sign_method )
146
148
147
149
if not result :
148
150
raise RuntimeError ('Failed to create template' )
@@ -177,7 +179,7 @@ def encrypted_data_create(
177
179
c_encoding = ctypes .c_char_p (encoding .encode ('utf-8' ) if encoding else None )
178
180
c_ns = ctypes .c_char_p (ns .encode ('utf-8' ) if ns else None )
179
181
180
- result = libxmlsec .PyXmlSec_TemplateEncryptedDataCreate (node , method , c_id , c_type , c_mime_type , c_encoding , c_ns )
182
+ result : _Element = libxmlsec .PyXmlSec_TemplateEncryptedDataCreate (node , method , c_id , c_type , c_mime_type , c_encoding , c_ns )
181
183
182
184
if not result :
183
185
raise RuntimeError ('Failed to create encrypted data' )
@@ -192,7 +194,7 @@ def encrypted_data_ensure_cipher_value(node: _Element) -> _Element:
192
194
:param node: The XML node to ensure cipher value for.
193
195
:return: The modified XML node.
194
196
"""
195
- result = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureCipherValue (node )
197
+ result : _Element = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureCipherValue (node )
196
198
197
199
if not result :
198
200
raise RuntimeError ('Failed to ensure cipher value' )
@@ -212,7 +214,7 @@ def encrypted_data_ensure_key_info(node: _Element, id: str | None = None, ns: st
212
214
c_id = ctypes .c_char_p (id .encode ('utf-8' ) if id else None )
213
215
c_ns = ctypes .c_char_p (ns .encode ('utf-8' ) if ns else None )
214
216
215
- result = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureKeyInfo (node , c_id , c_ns )
217
+ result : _Element = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureKeyInfo (node , c_id , c_ns )
216
218
217
219
if not result :
218
220
raise RuntimeError ('Failed to ensure key info' )
@@ -230,7 +232,7 @@ def ensure_key_info(node: _Element, id: str | None = None) -> _Element:
230
232
"""
231
233
c_id = ctypes .c_char_p (id .encode ('utf-8' ) if id else None )
232
234
233
- result = libxmlsec .PyXmlSec_TemplateEnsureKeyInfo (node , c_id )
235
+ result : _Element = libxmlsec .PyXmlSec_TemplateEnsureKeyInfo (node , c_id )
234
236
235
237
if not result :
236
238
raise RuntimeError ('Failed to ensure key info' )
@@ -250,7 +252,7 @@ def transform_add_c14n_inclusive_namespaces(node: _Element, prefixes: str | Sequ
250
252
251
253
c_prefixes = (ctypes .c_char_p * len (prefixes ))(* [p .encode ('utf-8' ) for p in prefixes ])
252
254
253
- result = libxmlsec .PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces (node , c_prefixes )
255
+ result : _Element = libxmlsec .PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces (node , c_prefixes )
254
256
255
257
if not result :
256
258
raise RuntimeError ('Failed to add inclusive namespaces' )
@@ -263,7 +265,7 @@ def x509_data_add_certificate(node: _Element) -> _Element:
263
265
:param node: The XML node to add the certificate to.
264
266
:return: The modified XML node.
265
267
"""
266
- result = libxmlsec .PyXmlSec_TemplateX509DataAddCertificate (node )
268
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddCertificate (node )
267
269
268
270
if not result :
269
271
raise RuntimeError ('Failed to add certificate' )
@@ -278,7 +280,7 @@ def x509_data_add_crl(node: _Element) -> _Element:
278
280
:param node: The XML node to add the CRL to.
279
281
:return: The modified XML node.
280
282
"""
281
- result = libxmlsec .PyXmlSec_TemplateX509DataAddCRL (node )
283
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddCRL (node )
282
284
283
285
if not result :
284
286
raise RuntimeError ('Failed to add CRL' )
@@ -293,7 +295,7 @@ def x509_data_add_issuer_serial(node: _Element) -> _Element:
293
295
:param node: The XML node to add the issuer serial to.
294
296
:return: The modified XML node.
295
297
"""
296
- result = libxmlsec .PyXmlSec_TemplateX509DataAddIssuerSerial (node )
298
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddIssuerSerial (node )
297
299
298
300
if not result :
299
301
raise RuntimeError ('Failed to add issuer serial' )
@@ -308,7 +310,7 @@ def x509_data_add_ski(node: _Element) -> _Element:
308
310
:param node: The XML node to add the SKI to.
309
311
:return: The modified XML node.
310
312
"""
311
- result = libxmlsec .PyXmlSec_TemplateX509DataAddSKI (node )
313
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddSKI (node )
312
314
313
315
if not result :
314
316
raise RuntimeError ('Failed to add SKI' )
@@ -323,7 +325,7 @@ def x509_data_add_subject_name(node: _Element) -> _Element:
323
325
:param node: The XML node to add the subject name to.
324
326
:return: The modified XML node.
325
327
"""
326
- result = libxmlsec .PyXmlSec_TemplateX509DataAddSubjectName (node )
328
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddSubjectName (node )
327
329
328
330
if not result :
329
331
raise RuntimeError ('Failed to add subject name' )
@@ -341,7 +343,7 @@ def x509_issuer_serial_add_issuer_name(node: _Element, name: str | None = None)
341
343
"""
342
344
c_name = ctypes .c_char_p (name .encode ('utf-8' ) if name else None )
343
345
344
- result = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddIssuerName (node , c_name )
346
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddIssuerName (node , c_name )
345
347
346
348
if not result :
347
349
raise RuntimeError ('Failed to add issuer name' )
@@ -359,7 +361,7 @@ def x509_issuer_serial_add_serial_number(node: _Element, serial: str | None = No
359
361
"""
360
362
c_serial = ctypes .c_char_p (serial .encode ('utf-8' ) if serial else None )
361
363
362
- result = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddSerialNumber (node , c_serial )
364
+ result : _Element = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddSerialNumber (node , c_serial )
363
365
364
366
if not result :
365
367
raise RuntimeError ('Failed to add serial number' )
0 commit comments