Skip to content

Commit cadfe8e

Browse files
committed
Migrate most verify type docs to type hints
1 parent 4007c19 commit cadfe8e

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
1313
pygments_style = "sphinx"
1414
autodoc_typehints = "description"
15+
typehints_fully_qualified = True
16+
always_document_param_types = True
1517

1618
if "readthedocs.org" in os.getcwd().split("/"):
1719
with open("index.rst", "w") as fh:

signxml/verifier.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from base64 import b64decode
22
from dataclasses import dataclass
3-
from typing import List, Optional
3+
from typing import Callable, List, Optional, Union
44

55
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa, utils
66
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
@@ -161,19 +161,19 @@ def _apply_transforms(self, payload, transforms_node, signature, c14n_algorithm)
161161
def verify(
162162
self,
163163
data,
164-
require_x509=True,
165-
x509_cert=None,
166-
cert_subject_name=None,
167-
cert_resolver=None,
168-
ca_pem_file=None,
169-
ca_path=None,
170-
hmac_key=None,
171-
validate_schema=True,
164+
require_x509: bool = True,
165+
x509_cert: Optional[Union[str, X509]] = None,
166+
cert_subject_name: Optional[str] = None,
167+
cert_resolver: Optional[Callable] = None,
168+
ca_pem_file: Optional[Union[str, bytes]] = None,
169+
ca_path: Optional[str] = None,
170+
hmac_key: Optional[str] = None,
171+
validate_schema: bool = True,
172172
parser=None,
173-
uri_resolver=None,
174-
id_attribute=None,
175-
expect_references=1,
176-
ignore_ambiguous_key_info=False,
173+
uri_resolver: Optional[Callable] = None,
174+
id_attribute: Optional[str] = None,
175+
expect_references: Union[int, bool] = 1,
176+
ignore_ambiguous_key_info: bool = False,
177177
) -> List[VerifyResult]:
178178
"""
179179
Verify the XML signature supplied in the data and return a list of **VerifyResult** data structures
@@ -210,59 +210,47 @@ def verify(
210210
:param require_x509:
211211
If ``True``, a valid X.509 certificate-based signature with an established chain of trust is required to
212212
pass validation. If ``False``, other types of valid signatures (e.g. HMAC or RSA public key) are accepted.
213-
:type require_x509: boolean
214213
:param x509_cert:
215214
A trusted external X.509 certificate, given as a PEM-formatted string or OpenSSL.crypto.X509 object, to use
216215
for verification. Overrides any X.509 certificate information supplied by the signature. If left set to
217216
``None``, requires that the signature supply a valid X.509 certificate chain that validates against the
218217
known certificate authorities. Implies **require_x509=True**.
219-
:type x509_cert: string or OpenSSL.crypto.X509
220218
:param cert_subject_name:
221219
Subject Common Name to check the signing X.509 certificate against. Implies **require_x509=True**.
222-
:type cert_subject_name: string
223220
:param cert_resolver:
224221
Function to use to resolve trusted X.509 certificates when X509IssuerSerial and X509Digest references are
225222
found in the signature. The function is called with the keyword arguments ``x509_issuer_name``,
226223
``x509_serial_number`` and ``x509_digest``, and is expected to return an iterable of one or more
227224
strings containing a PEM-formatted certificate and a chain of intermediate certificates, if needed.
228225
Implies **require_x509=True**.
229-
:type cert_resolver: callable
230226
:param ca_pem_file:
231227
Filename of a PEM file containing certificate authority information to use when verifying certificate-based
232228
signatures.
233-
:type ca_pem_file: string or bytes
234229
:param ca_path:
235230
Path to a directory containing PEM-formatted certificate authority files to use when verifying
236231
certificate-based signatures. If neither **ca_pem_file** nor **ca_path** is given, the Mozilla CA bundle
237232
provided by :py:mod:`certifi` will be loaded.
238-
:type ca_path: string
239233
:param hmac_key: If using HMAC, a string containing the shared secret.
240-
:type hmac_key: string
241234
:param validate_schema: Whether to validate **data** against the XML Signature schema.
242-
:type validate_schema: boolean
243235
:param parser:
244236
Custom XML parser instance to use when parsing **data**. The default parser arguments used by SignXML are:
245237
``resolve_entities=False``. See https://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint.
246238
:type parser: :py:class:`lxml.etree.XMLParser` compatible parser
247239
:param uri_resolver:
248240
Function to use to resolve reference URIs that don't start with "#". The function is called with a single
249241
string argument containing the URI to be resolved, and is expected to return a lxml.etree node or string.
250-
:type uri_resolver: callable
251242
:param id_attribute:
252243
Name of the attribute whose value ``URI`` refers to. By default, SignXML will search for "Id", then "ID".
253-
:type id_attribute: string
254244
:param expect_references:
255245
Number of references to expect in the signature. If this is not 1, an array of VerifyResults is returned.
256246
If set to a non-integer, any number of references is accepted (otherwise a mismatch raises an error).
257-
:type expect_references: int or boolean
258247
:param ignore_ambiguous_key_info:
259248
Ignore the presence of a KeyValue element when X509Data is present in the signature and used for verifying.
260249
The presence of both elements is an ambiguity and a security hazard. The public key used to sign the
261250
document is already encoded in the certificate (which is in X509Data), so the verifier must either ignore
262251
KeyValue or make sure it matches what's in the certificate. SignXML does not implement the functionality
263252
necessary to match the keys, and throws an InvalidInput error instead. Set this to True to bypass the error
264253
and validate the signature using X509Data only.
265-
:type ignore_ambiguous_key_info: boolean
266254
267255
:raises: :py:class:`cryptography.exceptions.InvalidSignature`
268256
"""

0 commit comments

Comments
 (0)