Skip to content

Commit 6b21a86

Browse files
committed
Documentation improvements
1 parent 2d8a54d commit 6b21a86

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

docs/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
release = ""
88
language = "en"
99
master_doc = "index"
10-
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
10+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode", "sphinx.ext.intersphinx"]
1111
source_suffix = [".rst", ".md"]
1212
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
1313
pygments_style = "sphinx"
1414
autodoc_member_order = "bysource"
1515
autodoc_typehints = "description"
1616
typehints_fully_qualified = True
1717
always_document_param_types = True
18+
intersphinx_mapping = {
19+
"https://docs.python.org/3": None,
20+
"https://lxml.de/apidoc": "https://lxml.de/apidoc/objects.inv",
21+
"https://cryptography.io/en/latest": "https://cryptography.io/en/latest/objects.inv",
22+
"https://www.pyopenssl.org/en/stable": "https://www.pyopenssl.org/en/stable/objects.inv",
23+
}
1824

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

signxml/algorithms.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def _missing_(cls, value):
5252

5353
class DigestAlgorithm(FragmentLookupMixin, InvalidInputErrorMixin, Enum):
5454
"""
55-
An enumeration of digest algorithms supported by SignXML. See RFC 9231 for details.
55+
An enumeration of digest algorithms supported by SignXML. See `RFC 9231
56+
<https://www.rfc-editor.org/rfc/rfc9231.html>`_ and the `Algorithm Identifiers and Implementation Requirements
57+
<http://www.w3.org/TR/xmldsig-core1/#sec-AlgID>`_ section of the XML Signature 1.1 standard for details.
5658
"""
5759

5860
SHA1 = "http://www.w3.org/2000/09/xmldsig#sha1"
@@ -76,8 +78,9 @@ def implementation(self) -> Callable:
7678
# TODO: check if padding errors are fixed by using padding=MGF1
7779
class SignatureMethod(FragmentLookupMixin, InvalidInputErrorMixin, Enum):
7880
"""
79-
An enumeration of signature methods (also referred to as signature algorithms) supported by SignXML. See RFC 9231
80-
for details.
81+
An enumeration of signature methods (also referred to as signature algorithms) supported by SignXML. See `RFC 9231
82+
<https://www.rfc-editor.org/rfc/rfc9231.html>`_ and the `Algorithm Identifiers and Implementation Requirements
83+
<http://www.w3.org/TR/xmldsig-core1/#sec-AlgID>`_ section of the XML Signature 1.1 standard for details.
8184
"""
8285

8386
DSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#dsa-sha1"
@@ -109,7 +112,9 @@ class SignatureMethod(FragmentLookupMixin, InvalidInputErrorMixin, Enum):
109112
class CanonicalizationMethod(InvalidInputErrorMixin, Enum):
110113
"""
111114
An enumeration of XML canonicalization methods (also referred to as canonicalization algorithms) supported by
112-
SignXML. See RFC 9231 for details.
115+
SignXML. See `RFC 9231 <https://www.rfc-editor.org/rfc/rfc9231.html>`_ and the `Algorithm Identifiers and
116+
Implementation Requirements <http://www.w3.org/TR/xmldsig-core1/#sec-AlgID>`_ section of the XML Signature 1.1
117+
standard for details.
113118
"""
114119

115120
CANONICAL_XML_1_0 = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"

signxml/signer.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from cryptography.hazmat.primitives.hmac import HMAC
88
from cryptography.hazmat.primitives.serialization import load_pem_private_key
99
from lxml.etree import Element, SubElement, _Element
10-
from OpenSSL.crypto import FILETYPE_PEM, dump_certificate
10+
from OpenSSL.crypto import FILETYPE_PEM, X509, dump_certificate
1111

1212
from .algorithms import (
1313
CanonicalizationMethod,
@@ -62,13 +62,14 @@ class XMLSigner(XMLSignatureProcessor):
6262
``signxml.methods.enveloped``, ``signxml.methods.enveloping``, or ``signxml.methods.detached``. See
6363
:class:`SignatureConstructionMethod` for details.
6464
:param signature_algorithm:
65-
Algorithm that will be used to generate the signature, composed of the signature algorithm and the digest
66-
algorithm, separated by a hyphen. All algorithm IDs listed under the `Algorithm Identifiers and
67-
Implementation Requirements <http://www.w3.org/TR/xmldsig-core1/#sec-AlgID>`_ section of the XML Signature
68-
1.1 standard are supported.
69-
:param digest_algorithm: Algorithm that will be used to hash the data during signature generation. All algorithm IDs
70-
listed under the `Algorithm Identifiers and Implementation Requirements
71-
<http://www.w3.org/TR/xmldsig-core1/#sec-AlgID>`_ section of the XML Signature 1.1 standard are supported.
65+
Algorithm that will be used to generate the signature. See :class:`SignatureMethod` for the list of algorithm
66+
IDs supported.
67+
:param digest_algorithm:
68+
Algorithm that will be used to hash the data during signature generation. See :class:`DigestAlgorithm` for the
69+
list of algorithm IDs supported.
70+
:param c14n_algorithm:
71+
Algorithm that will be used to canonicalize (serialize in a reproducible way) the XML that is signed. See
72+
:class:`CanonicalizationMethod` for the list of algorithm IDs supported.
7273
"""
7374

7475
signature_annotators: List
@@ -92,7 +93,7 @@ def __init__(
9293
method: SignatureConstructionMethod = SignatureConstructionMethod.enveloped,
9394
signature_algorithm: Union[SignatureMethod, str] = SignatureMethod.RSA_SHA256,
9495
digest_algorithm: Union[DigestAlgorithm, str] = DigestAlgorithm.SHA256,
95-
c14n_algorithm=CanonicalizationMethod.CANONICAL_XML_1_1,
96+
c14n_algorithm: Union[CanonicalizationMethod, str] = CanonicalizationMethod.CANONICAL_XML_1_1,
9697
):
9798
if method is None or method not in SignatureConstructionMethod:
9899
raise InvalidInput(f"Unknown signature construction method {method}")
@@ -115,14 +116,14 @@ def sign(
115116
data,
116117
key=None,
117118
passphrase: Optional[bytes] = None,
118-
cert=None,
119+
cert: Optional[Union[str, List[str], List[X509]]] = None,
119120
reference_uri: Optional[Union[str, List[str], List[XMLSignatureReference]]] = None,
120121
key_name: Optional[str] = None,
121122
key_info: Optional[_Element] = None,
122123
id_attribute: Optional[str] = None,
123124
always_add_key_value: bool = False,
124125
inclusive_ns_prefixes: Optional[List[str]] = None,
125-
signature_properties=None,
126+
signature_properties: Optional[Union[_Element, List[_Element]]] = None,
126127
) -> _Element:
127128
"""
128129
Sign the data and return the root element of the resulting XML tree.
@@ -131,20 +132,19 @@ def sign(
131132
:type data: String, file-like object, or XML ElementTree Element API compatible object
132133
:param key:
133134
Key to be used for signing. When signing with a certificate or RSA/DSA/ECDSA key, this can be a string/bytes
134-
containing a PEM-formatted key, or a :py:class:`cryptography.hazmat.primitives.interfaces.RSAPrivateKey`,
135-
:py:class:`cryptography.hazmat.primitives.interfaces.DSAPrivateKey`, or
136-
:py:class:`cryptography.hazmat.primitives.interfaces.EllipticCurvePrivateKey` object. When signing with a
135+
containing a PEM-formatted key, or a :class:`cryptography.hazmat.primitives.interfaces.RSAPrivateKey`,
136+
:class:`cryptography.hazmat.primitives.interfaces.DSAPrivateKey`, or
137+
:class:`cryptography.hazmat.primitives.interfaces.EllipticCurvePrivateKey` object. When signing with a
137138
HMAC, this should be a string containing the shared secret.
138139
:type key:
139-
string, bytes, :py:class:`cryptography.hazmat.primitives.interfaces.RSAPrivateKey`,
140-
:py:class:`cryptography.hazmat.primitives.interfaces.DSAPrivateKey`, or
141-
:py:class:`cryptography.hazmat.primitives.interfaces.EllipticCurvePrivateKey` object
140+
string, bytes, :class:`cryptography.hazmat.primitives.interfaces.RSAPrivateKey`,
141+
:class:`cryptography.hazmat.primitives.interfaces.DSAPrivateKey`, or
142+
:class:`cryptography.hazmat.primitives.interfaces.EllipticCurvePrivateKey` object
142143
:param passphrase: Passphrase to use to decrypt the key, if any.
143144
:param cert:
144145
X.509 certificate to use for signing. This should be a string containing a PEM-formatted certificate, or an
145-
array of strings or OpenSSL.crypto.X509 objects containing the certificate and a chain of intermediate
146-
certificates.
147-
:type cert: string, array of strings, or array of OpenSSL.crypto.X509 objects
146+
array of strings or :class:`OpenSSL.crypto.X509` objects containing the certificate and a chain of
147+
intermediate certificates.
148148
:param reference_uri:
149149
Custom reference URI or list of reference URIs to incorporate into the signature. When ``method`` is set to
150150
``detached`` or ``enveloped``, reference URIs are set to this value and only the referenced elements are
@@ -175,10 +175,9 @@ def sign(
175175
:param signature_properties:
176176
One or more Elements that are to be included in the SignatureProperies section when using the detached
177177
method.
178-
:type signature_properties: :py:class:`lxml.etree.Element` or list of :py:class:`lxml.etree.Element` s
179178
180179
:returns:
181-
A :py:class:`lxml.etree.Element` object representing the root of the XML tree containing the signature and
180+
A :class:`lxml.etree._Element` object representing the root of the XML tree containing the signature and
182181
the payload data.
183182
184183
To specify the location of an enveloped signature within **data**, insert a
@@ -192,7 +191,7 @@ def sign(
192191
if isinstance(cert, (str, bytes)):
193192
cert_chain = list(iterate_pem(cert))
194193
else:
195-
cert_chain = cert
194+
cert_chain = cert # type: ignore
196195

197196
input_references = self._preprocess_reference_uri(reference_uri)
198197

signxml/verifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def verify(
242242
:param parser:
243243
Custom XML parser instance to use when parsing **data**. The default parser arguments used by SignXML are:
244244
``resolve_entities=False``. See https://lxml.de/FAQ.html#how-do-i-use-lxml-safely-as-a-web-service-endpoint.
245-
:type parser: :py:class:`lxml.etree.XMLParser` compatible parser
245+
:type parser: :class:`lxml.etree.XMLParser` compatible parser
246246
:param uri_resolver:
247247
Function to use to resolve reference URIs that don't start with "#". The function is called with a single
248248
string argument containing the URI to be resolved, and is expected to return a lxml.etree node or string.
@@ -259,7 +259,7 @@ def verify(
259259
necessary to match the keys, and throws an InvalidInput error instead. Set this to True to bypass the error
260260
and validate the signature using X509Data only.
261261
262-
:raises: :py:class:`cryptography.exceptions.InvalidSignature`
262+
:raises: :class:`signxml.exceptions.InvalidSignature`
263263
"""
264264
self.hmac_key = hmac_key
265265
self.require_x509 = require_x509

0 commit comments

Comments
 (0)