Skip to content

Commit 9080da1

Browse files
committed
Replace template.pyi with template.py
1 parent e18c0c6 commit 9080da1

File tree

2 files changed

+322
-38
lines changed

2 files changed

+322
-38
lines changed

src/xmlsec/template.py

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,325 @@ def add_encrypted_key(
4343
raise RuntimeError('Failed to add encrypted key')
4444

4545
return result
46+
47+
48+
def add_key_name(node: _Element, name: str | None = None) -> _Element:
49+
"""
50+
Python wrapper for the C function `PyXmlSec_TemplateAddKeyName`.
51+
52+
:param node: The XML node to which the key name will be added.
53+
:param name: Optional name for the key.
54+
:return: The modified XML node.
55+
"""
56+
c_name = ctypes.c_char_p(name.encode('utf-8') if name else None)
57+
result = libxmlsec.PyXmlSec_TemplateAddKeyName(node, c_name)
58+
59+
if not result:
60+
raise RuntimeError('Failed to add key name')
61+
62+
return result
63+
64+
65+
def add_key_value(node: _Element) -> _Element:
66+
"""
67+
Python wrapper for the C function `PyXmlSec_TemplateAddKeyValue`.
68+
69+
:param node: The XML node to which the key value will be added.
70+
:return: The modified XML node.
71+
"""
72+
result = libxmlsec.PyXmlSec_TemplateAddKeyValue(node)
73+
74+
if not result:
75+
raise RuntimeError('Failed to add key value')
76+
77+
return result
78+
79+
80+
def add_reference(
81+
node: _Element, digest_method: Transform, id: str | None = None, uri: str | None = None, type: str | None = None
82+
) -> _Element:
83+
"""
84+
Python wrapper for the C function `PyXmlSec_TemplateAddReference`.
85+
86+
:param node: The XML node to which the reference will be added.
87+
:param digest_method: The digest method for the reference.
88+
:param id: Optional ID for the reference.
89+
:param uri: Optional URI for the reference.
90+
:param type: Optional type for the reference.
91+
:return: The modified XML node.
92+
"""
93+
c_id = ctypes.c_char_p(id.encode('utf-8') if id else None)
94+
c_uri = ctypes.c_char_p(uri.encode('utf-8') if uri else None)
95+
c_type = ctypes.c_char_p(type.encode('utf-8') if type else None)
96+
97+
result = libxmlsec.PyXmlSec_TemplateAddReference(node, digest_method, c_id, c_uri, c_type)
98+
99+
if not result:
100+
raise RuntimeError('Failed to add reference')
101+
102+
return result
103+
104+
105+
def add_transform(node: _Element, transform: Transform) -> Any:
106+
"""
107+
Python wrapper for the C function `PyXmlSec_TemplateAddTransform`.
108+
109+
:param node: The XML node to which the transform will be added.
110+
:param transform: The transform to add.
111+
:return: The modified XML node.
112+
"""
113+
result = libxmlsec.PyXmlSec_TemplateAddTransform(node, transform)
114+
115+
if not result:
116+
raise RuntimeError('Failed to add transform')
117+
118+
return result
119+
120+
121+
def add_x509_data(node: _Element) -> _Element:
122+
"""
123+
Python wrapper for the C function `PyXmlSec_TemplateAddX509Data`.
124+
125+
:param node: The XML node to which the X509 data will be added.
126+
:return: The modified XML node.
127+
"""
128+
result = libxmlsec.PyXmlSec_TemplateAddX509Data(node)
129+
130+
if not result:
131+
raise RuntimeError('Failed to add X509 data')
132+
133+
return result
134+
135+
136+
def create(node: _Element, c14n_method: Transform, sign_method: Transform) -> _Element:
137+
"""
138+
Python wrapper for the C function `PyXmlSec_TemplateCreate`.
139+
140+
:param node: The XML node to create.
141+
:param c14n_method: The canonicalization method.
142+
:param sign_method: The signature method.
143+
:return: The created XML node.
144+
"""
145+
result = libxmlsec.PyXmlSec_TemplateCreate(node, c14n_method, sign_method)
146+
147+
if not result:
148+
raise RuntimeError('Failed to create template')
149+
150+
return result
151+
152+
153+
def encrypted_data_create(
154+
node: _Element,
155+
method: Transform,
156+
id: str | None = None,
157+
type: str | None = None,
158+
mime_type: str | None = None,
159+
encoding: str | None = None,
160+
ns: str | None = None,
161+
) -> _Element:
162+
"""
163+
Python wrapper for the C function `PyXmlSec_TemplateEncryptedDataCreate`.
164+
165+
:param node: The XML node to create encrypted data for.
166+
:param method: The encryption method.
167+
:param id: Optional ID for the encrypted data.
168+
:param type: Optional type for the encrypted data.
169+
:param mime_type: Optional MIME type for the encrypted data.
170+
:param encoding: Optional encoding for the encrypted data.
171+
:param ns: Optional namespace for the encrypted data.
172+
:return: The created encrypted data node.
173+
"""
174+
c_id = ctypes.c_char_p(id.encode('utf-8') if id else None)
175+
c_type = ctypes.c_char_p(type.encode('utf-8') if type else None)
176+
c_mime_type = ctypes.c_char_p(mime_type.encode('utf-8') if mime_type else None)
177+
c_encoding = ctypes.c_char_p(encoding.encode('utf-8') if encoding else None)
178+
c_ns = ctypes.c_char_p(ns.encode('utf-8') if ns else None)
179+
180+
result = libxmlsec.PyXmlSec_TemplateEncryptedDataCreate(node, method, c_id, c_type, c_mime_type, c_encoding, c_ns)
181+
182+
if not result:
183+
raise RuntimeError('Failed to create encrypted data')
184+
185+
return result
186+
187+
188+
def encrypted_data_ensure_cipher_value(node: _Element) -> _Element:
189+
"""
190+
Python wrapper for the C function `PyXmlSec_TemplateEncryptedDataEnsureCipherValue`.
191+
192+
:param node: The XML node to ensure cipher value for.
193+
:return: The modified XML node.
194+
"""
195+
result = libxmlsec.PyXmlSec_TemplateEncryptedDataEnsureCipherValue(node)
196+
197+
if not result:
198+
raise RuntimeError('Failed to ensure cipher value')
199+
200+
return result
201+
202+
203+
def encrypted_data_ensure_key_info(node: _Element, id: str | None = None, ns: str | None = None) -> _Element:
204+
"""
205+
Python wrapper for the C function `PyXmlSec_TemplateEncryptedDataEnsureKeyInfo`.
206+
207+
:param node: The XML node to ensure key info for.
208+
:param id: Optional ID for the key info.
209+
:param ns: Optional namespace for the key info.
210+
:return: The modified XML node.
211+
"""
212+
c_id = ctypes.c_char_p(id.encode('utf-8') if id else None)
213+
c_ns = ctypes.c_char_p(ns.encode('utf-8') if ns else None)
214+
215+
result = libxmlsec.PyXmlSec_TemplateEncryptedDataEnsureKeyInfo(node, c_id, c_ns)
216+
217+
if not result:
218+
raise RuntimeError('Failed to ensure key info')
219+
220+
return result
221+
222+
223+
def ensure_key_info(node: _Element, id: str | None = None) -> _Element:
224+
"""
225+
Python wrapper for the C function `PyXmlSec_TemplateEnsureKeyInfo`.
226+
227+
:param node: The XML node to ensure key info for.
228+
:param id: Optional ID for the key info.
229+
:return: The modified XML node.
230+
"""
231+
c_id = ctypes.c_char_p(id.encode('utf-8') if id else None)
232+
233+
result = libxmlsec.PyXmlSec_TemplateEnsureKeyInfo(node, c_id)
234+
235+
if not result:
236+
raise RuntimeError('Failed to ensure key info')
237+
238+
return result
239+
240+
241+
def transform_add_c14n_inclusive_namespaces(node: _Element, prefixes: str | Sequence[str]) -> None:
242+
"""
243+
Python wrapper for the C function `PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces`.
244+
245+
:param node: The XML node to add inclusive namespaces to.
246+
:param prefixes: The prefixes to add.
247+
"""
248+
if isinstance(prefixes, str):
249+
prefixes = [prefixes]
250+
251+
c_prefixes = (ctypes.c_char_p * len(prefixes))(*[p.encode('utf-8') for p in prefixes])
252+
253+
result = libxmlsec.PyXmlSec_TemplateTransformAddC14NInclusiveNamespaces(node, c_prefixes)
254+
255+
if not result:
256+
raise RuntimeError('Failed to add inclusive namespaces')
257+
258+
259+
def x509_data_add_certificate(node: _Element) -> _Element:
260+
"""
261+
Python wrapper for the C function `PyXmlSec_TemplateX509DataAddCertificate`.
262+
263+
:param node: The XML node to add the certificate to.
264+
:return: The modified XML node.
265+
"""
266+
result = libxmlsec.PyXmlSec_TemplateX509DataAddCertificate(node)
267+
268+
if not result:
269+
raise RuntimeError('Failed to add certificate')
270+
271+
return result
272+
273+
274+
def x509_data_add_crl(node: _Element) -> _Element:
275+
"""
276+
Python wrapper for the C function `PyXmlSec_TemplateX509DataAddCRL`.
277+
278+
:param node: The XML node to add the CRL to.
279+
:return: The modified XML node.
280+
"""
281+
result = libxmlsec.PyXmlSec_TemplateX509DataAddCRL(node)
282+
283+
if not result:
284+
raise RuntimeError('Failed to add CRL')
285+
286+
return result
287+
288+
289+
def x509_data_add_issuer_serial(node: _Element) -> _Element:
290+
"""
291+
Python wrapper for the C function `PyXmlSec_TemplateX509DataAddIssuerSerial`.
292+
293+
:param node: The XML node to add the issuer serial to.
294+
:return: The modified XML node.
295+
"""
296+
result = libxmlsec.PyXmlSec_TemplateX509DataAddIssuerSerial(node)
297+
298+
if not result:
299+
raise RuntimeError('Failed to add issuer serial')
300+
301+
return result
302+
303+
304+
def x509_data_add_ski(node: _Element) -> _Element:
305+
"""
306+
Python wrapper for the C function `PyXmlSec_TemplateX509DataAddSKI`.
307+
308+
:param node: The XML node to add the SKI to.
309+
:return: The modified XML node.
310+
"""
311+
result = libxmlsec.PyXmlSec_TemplateX509DataAddSKI(node)
312+
313+
if not result:
314+
raise RuntimeError('Failed to add SKI')
315+
316+
return result
317+
318+
319+
def x509_data_add_subject_name(node: _Element) -> _Element:
320+
"""
321+
Python wrapper for the C function `PyXmlSec_TemplateX509DataAddSubjectName`.
322+
323+
:param node: The XML node to add the subject name to.
324+
:return: The modified XML node.
325+
"""
326+
result = libxmlsec.PyXmlSec_TemplateX509DataAddSubjectName(node)
327+
328+
if not result:
329+
raise RuntimeError('Failed to add subject name')
330+
331+
return result
332+
333+
334+
def x509_issuer_serial_add_issuer_name(node: _Element, name: str | None = None) -> _Element:
335+
"""
336+
Python wrapper for the C function `PyXmlSec_TemplateX509IssuerSerialAddIssuerName`.
337+
338+
:param node: The XML node to add the issuer name to.
339+
:param name: The issuer name to add.
340+
:return: The modified XML node.
341+
"""
342+
c_name = ctypes.c_char_p(name.encode('utf-8') if name else None)
343+
344+
result = libxmlsec.PyXmlSec_TemplateX509IssuerSerialAddIssuerName(node, c_name)
345+
346+
if not result:
347+
raise RuntimeError('Failed to add issuer name')
348+
349+
return result
350+
351+
352+
def x509_issuer_serial_add_serial_number(node: _Element, serial: str | None = None) -> _Element:
353+
"""
354+
Python wrapper for the C function `PyXmlSec_TemplateX509IssuerSerialAddSerialNumber`.
355+
356+
:param node: The XML node to add the serial number to.
357+
:param serial: The serial number to add.
358+
:return: The modified XML node.
359+
"""
360+
c_serial = ctypes.c_char_p(serial.encode('utf-8') if serial else None)
361+
362+
result = libxmlsec.PyXmlSec_TemplateX509IssuerSerialAddSerialNumber(node, c_serial)
363+
364+
if not result:
365+
raise RuntimeError('Failed to add serial number')
366+
367+
return result

src/xmlsec/template.pyi

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)