Skip to content

Commit

Permalink
Document experimental reporting API
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasValvekens committed Nov 18, 2023
1 parent 786b829 commit ff6b23e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/api-docs/pyhanko.sign.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subpackages
-----------

.. toctree::
:maxdepth: 4
:maxdepth: 2

pyhanko.sign.ades
pyhanko.sign.diff_analysis
Expand Down
14 changes: 14 additions & 0 deletions docs/api-docs/pyhanko.sign.validation.report.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pyhanko.sign.validation.report package
======================================


Submodules
----------

pyhanko.sign.validation.report.tools module
-------------------------------------------

.. automodule:: pyhanko.sign.validation.report.tools
:members:
:undoc-members:
:show-inheritance:
9 changes: 9 additions & 0 deletions docs/api-docs/pyhanko.sign.validation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pyhanko.sign.validation package
===============================

Subpackages
-----------

.. toctree::
:maxdepth: 2

pyhanko.sign.validation.report


Submodules
----------

Expand Down
Empty file.
24 changes: 24 additions & 0 deletions pyhanko/sign/validation/report/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
ETSI TS 119 102-2 reporting functionality.
.. info:
This module requires optional ``[etsi]`` dependency group,
and only works on Python 3.8+ for dependency reasons.
.. warning::
This feature is incubating and subject to API changes.
"""

from typing import Any, Dict, Optional, cast

from asn1crypto import tsp
Expand Down Expand Up @@ -26,6 +37,8 @@
from pyhanko.sign.validation.pdf_embedded import EmbeddedPdfSignature
from pyhanko.sign.validation.status import PdfSignatureStatus

__all__ = ['generate_report']

DIGEST_ALGO_URIS = {
'sha1': 'http://www.w3.org/2000/09/xmldsig#sha1',
'sha256': 'http://www.w3.org/2001/04/xmlenc#sha256',
Expand Down Expand Up @@ -357,6 +370,17 @@ def _package_validation_object(vo: ValidationObject):
def generate_report(
embedded_sig: EmbeddedPdfSignature, status: AdESBasicValidationResult
) -> str:
"""
Generate signature validation report in XML format according to
ETSI TS 119 102-2.
:param embedded_sig:
PDF signature to report on.
:param status:
AdES validation result to turn into a report.
:return:
A string representation of the validation report.
"""
report = ts_11910202.ValidationReport(
signature_validation_report=(_generate_report(embedded_sig, status),),
signature_validation_objects=ts_11910202.ValidationObjectListType(
Expand Down

0 comments on commit ff6b23e

Please sign in to comment.