11import ctypes
2+ from collections .abc import Sequence
3+ from typing import Any
24
35from lxml .etree import _Element
46
@@ -37,7 +39,7 @@ def add_encrypted_key(
3739 c_recipient = ctypes .c_char_p (recipient .encode ('utf-8' ) if recipient else None )
3840
3941 # 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 )
4143
4244 if not result :
4345 raise RuntimeError ('Failed to add encrypted key' )
@@ -54,7 +56,7 @@ def add_key_name(node: _Element, name: str | None = None) -> _Element:
5456 :return: The modified XML node.
5557 """
5658 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 )
5860
5961 if not result :
6062 raise RuntimeError ('Failed to add key name' )
@@ -69,7 +71,7 @@ def add_key_value(node: _Element) -> _Element:
6971 :param node: The XML node to which the key value will be added.
7072 :return: The modified XML node.
7173 """
72- result = libxmlsec .PyXmlSec_TemplateAddKeyValue (node )
74+ result : _Element = libxmlsec .PyXmlSec_TemplateAddKeyValue (node )
7375
7476 if not result :
7577 raise RuntimeError ('Failed to add key value' )
@@ -94,7 +96,7 @@ def add_reference(
9496 c_uri = ctypes .c_char_p (uri .encode ('utf-8' ) if uri else None )
9597 c_type = ctypes .c_char_p (type .encode ('utf-8' ) if type else None )
9698
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 )
98100
99101 if not result :
100102 raise RuntimeError ('Failed to add reference' )
@@ -110,7 +112,7 @@ def add_transform(node: _Element, transform: Transform) -> Any:
110112 :param transform: The transform to add.
111113 :return: The modified XML node.
112114 """
113- result = libxmlsec .PyXmlSec_TemplateAddTransform (node , transform )
115+ result : _Element = libxmlsec .PyXmlSec_TemplateAddTransform (node , transform )
114116
115117 if not result :
116118 raise RuntimeError ('Failed to add transform' )
@@ -125,7 +127,7 @@ def add_x509_data(node: _Element) -> _Element:
125127 :param node: The XML node to which the X509 data will be added.
126128 :return: The modified XML node.
127129 """
128- result = libxmlsec .PyXmlSec_TemplateAddX509Data (node )
130+ result : _Element = libxmlsec .PyXmlSec_TemplateAddX509Data (node )
129131
130132 if not result :
131133 raise RuntimeError ('Failed to add X509 data' )
@@ -142,7 +144,7 @@ def create(node: _Element, c14n_method: Transform, sign_method: Transform) -> _E
142144 :param sign_method: The signature method.
143145 :return: The created XML node.
144146 """
145- result = libxmlsec .PyXmlSec_TemplateCreate (node , c14n_method , sign_method )
147+ result : _Element = libxmlsec .PyXmlSec_TemplateCreate (node , c14n_method , sign_method )
146148
147149 if not result :
148150 raise RuntimeError ('Failed to create template' )
@@ -177,7 +179,7 @@ def encrypted_data_create(
177179 c_encoding = ctypes .c_char_p (encoding .encode ('utf-8' ) if encoding else None )
178180 c_ns = ctypes .c_char_p (ns .encode ('utf-8' ) if ns else None )
179181
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 )
181183
182184 if not result :
183185 raise RuntimeError ('Failed to create encrypted data' )
@@ -192,7 +194,7 @@ def encrypted_data_ensure_cipher_value(node: _Element) -> _Element:
192194 :param node: The XML node to ensure cipher value for.
193195 :return: The modified XML node.
194196 """
195- result = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureCipherValue (node )
197+ result : _Element = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureCipherValue (node )
196198
197199 if not result :
198200 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
212214 c_id = ctypes .c_char_p (id .encode ('utf-8' ) if id else None )
213215 c_ns = ctypes .c_char_p (ns .encode ('utf-8' ) if ns else None )
214216
215- result = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureKeyInfo (node , c_id , c_ns )
217+ result : _Element = libxmlsec .PyXmlSec_TemplateEncryptedDataEnsureKeyInfo (node , c_id , c_ns )
216218
217219 if not result :
218220 raise RuntimeError ('Failed to ensure key info' )
@@ -230,7 +232,7 @@ def ensure_key_info(node: _Element, id: str | None = None) -> _Element:
230232 """
231233 c_id = ctypes .c_char_p (id .encode ('utf-8' ) if id else None )
232234
233- result = libxmlsec .PyXmlSec_TemplateEnsureKeyInfo (node , c_id )
235+ result : _Element = libxmlsec .PyXmlSec_TemplateEnsureKeyInfo (node , c_id )
234236
235237 if not result :
236238 raise RuntimeError ('Failed to ensure key info' )
@@ -250,7 +252,7 @@ def transform_add_c14n_inclusive_namespaces(node: _Element, prefixes: str | Sequ
250252
251253 c_prefixes = (ctypes .c_char_p * len (prefixes ))(* [p .encode ('utf-8' ) for p in prefixes ])
252254
253- result = libxmlsec .PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces (node , c_prefixes )
255+ result : _Element = libxmlsec .PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces (node , c_prefixes )
254256
255257 if not result :
256258 raise RuntimeError ('Failed to add inclusive namespaces' )
@@ -263,7 +265,7 @@ def x509_data_add_certificate(node: _Element) -> _Element:
263265 :param node: The XML node to add the certificate to.
264266 :return: The modified XML node.
265267 """
266- result = libxmlsec .PyXmlSec_TemplateX509DataAddCertificate (node )
268+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddCertificate (node )
267269
268270 if not result :
269271 raise RuntimeError ('Failed to add certificate' )
@@ -278,7 +280,7 @@ def x509_data_add_crl(node: _Element) -> _Element:
278280 :param node: The XML node to add the CRL to.
279281 :return: The modified XML node.
280282 """
281- result = libxmlsec .PyXmlSec_TemplateX509DataAddCRL (node )
283+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddCRL (node )
282284
283285 if not result :
284286 raise RuntimeError ('Failed to add CRL' )
@@ -293,7 +295,7 @@ def x509_data_add_issuer_serial(node: _Element) -> _Element:
293295 :param node: The XML node to add the issuer serial to.
294296 :return: The modified XML node.
295297 """
296- result = libxmlsec .PyXmlSec_TemplateX509DataAddIssuerSerial (node )
298+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddIssuerSerial (node )
297299
298300 if not result :
299301 raise RuntimeError ('Failed to add issuer serial' )
@@ -308,7 +310,7 @@ def x509_data_add_ski(node: _Element) -> _Element:
308310 :param node: The XML node to add the SKI to.
309311 :return: The modified XML node.
310312 """
311- result = libxmlsec .PyXmlSec_TemplateX509DataAddSKI (node )
313+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddSKI (node )
312314
313315 if not result :
314316 raise RuntimeError ('Failed to add SKI' )
@@ -323,7 +325,7 @@ def x509_data_add_subject_name(node: _Element) -> _Element:
323325 :param node: The XML node to add the subject name to.
324326 :return: The modified XML node.
325327 """
326- result = libxmlsec .PyXmlSec_TemplateX509DataAddSubjectName (node )
328+ result : _Element = libxmlsec .PyXmlSec_TemplateX509DataAddSubjectName (node )
327329
328330 if not result :
329331 raise RuntimeError ('Failed to add subject name' )
@@ -341,7 +343,7 @@ def x509_issuer_serial_add_issuer_name(node: _Element, name: str | None = None)
341343 """
342344 c_name = ctypes .c_char_p (name .encode ('utf-8' ) if name else None )
343345
344- result = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddIssuerName (node , c_name )
346+ result : _Element = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddIssuerName (node , c_name )
345347
346348 if not result :
347349 raise RuntimeError ('Failed to add issuer name' )
@@ -359,7 +361,7 @@ def x509_issuer_serial_add_serial_number(node: _Element, serial: str | None = No
359361 """
360362 c_serial = ctypes .c_char_p (serial .encode ('utf-8' ) if serial else None )
361363
362- result = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddSerialNumber (node , c_serial )
364+ result : _Element = libxmlsec .PyXmlSec_TemplateX509IssuerSerialAddSerialNumber (node , c_serial )
363365
364366 if not result :
365367 raise RuntimeError ('Failed to add serial number' )
0 commit comments