diff --git a/external-schemata/genxml.sh b/external-schemata/genxml.sh index 8563b60e..12000a72 100755 --- a/external-schemata/genxml.sh +++ b/external-schemata/genxml.sh @@ -1,4 +1,7 @@ #!/bin/bash + +pip install 'ruff>=0.3.0' + xsdata generate \ --config ./external-schemata/.xsdata.xml \ -p pyhanko.generated \ @@ -6,4 +9,4 @@ xsdata generate \ ./external-schemata/xsd/ isort --profile black --line-length 80 pyhanko/generated -black -S --line-length 80 pyhanko/generated \ No newline at end of file +black -S --line-length 80 pyhanko/generated diff --git a/pyhanko/generated/etsi/ts_11910202.py b/pyhanko/generated/etsi/ts_11910202.py index 7dc713df..cd23ad43 100644 --- a/pyhanko/generated/etsi/ts_11910202.py +++ b/pyhanko/generated/etsi/ts_11910202.py @@ -4,7 +4,12 @@ from xsdata.models.datatype import XmlDateTime -from ..w3c.xmldsig_core import DigestMethod, Signature, SignatureValue +from ..w3c.xmldsig_core import ( + DigestMethod, + DigestValue, + Signature, + SignatureValue, +) from .ts_119612 import DigitalIdentityType, TSPInformationType from .xades import DigestAlgAndValueType, SignaturePolicyIdentifierType @@ -186,7 +191,6 @@ class VOReferenceType: metadata={ "name": "VOReference", "type": "Attribute", - "required": True, "tokens": True, }, ) @@ -400,14 +404,13 @@ class SACRLIDType: "required": True, }, ) - digest_value: Optional[bytes] = field( + digest_value: Optional[DigestValue] = field( default=None, metadata={ "name": "DigestValue", "type": "Element", "namespace": "http://www.w3.org/2000/09/xmldsig#", "required": True, - "format": "base64", }, ) @@ -432,14 +435,13 @@ class SACertIDType: "required": True, }, ) - digest_value: Optional[bytes] = field( + digest_value: Optional[DigestValue] = field( default=None, metadata={ "name": "DigestValue", "type": "Element", "namespace": "http://www.w3.org/2000/09/xmldsig#", "required": True, - "format": "base64", }, ) diff --git a/pyhanko/generated/etsi/ts_119612.py b/pyhanko/generated/etsi/ts_119612.py index 97535455..52b73327 100644 --- a/pyhanko/generated/etsi/ts_119612.py +++ b/pyhanko/generated/etsi/ts_119612.py @@ -572,14 +572,13 @@ class ServiceDigitalIdentityListType: @dataclass(frozen=True) class ServiceHistoryInstanceType: - service_type_identifier: Optional[str] = field( + service_type_identifier: Optional[ServiceTypeIdentifier] = field( default=None, metadata={ "name": "ServiceTypeIdentifier", "type": "Element", "namespace": "http://uri.etsi.org/02231/v2#", "required": True, - "min_length": 1, }, ) service_name: Optional[InternationalNamesType] = field( @@ -600,14 +599,13 @@ class ServiceHistoryInstanceType: "required": True, }, ) - service_status: Optional[str] = field( + service_status: Optional[ServiceStatus] = field( default=None, metadata={ "name": "ServiceStatus", "type": "Element", "namespace": "http://uri.etsi.org/02231/v2#", "required": True, - "min_length": 1, }, ) status_starting_time: Optional[XmlDateTime] = field( @@ -631,14 +629,13 @@ class ServiceHistoryInstanceType: @dataclass(frozen=True) class TSPServiceInformationType: - service_type_identifier: Optional[str] = field( + service_type_identifier: Optional[ServiceTypeIdentifier] = field( default=None, metadata={ "name": "ServiceTypeIdentifier", "type": "Element", "namespace": "http://uri.etsi.org/02231/v2#", "required": True, - "min_length": 1, }, ) service_name: Optional[InternationalNamesType] = field( @@ -659,14 +656,13 @@ class TSPServiceInformationType: "required": True, }, ) - service_status: Optional[str] = field( + service_status: Optional[ServiceStatus] = field( default=None, metadata={ "name": "ServiceStatus", "type": "Element", "namespace": "http://uri.etsi.org/02231/v2#", "required": True, - "min_length": 1, }, ) status_starting_time: Optional[XmlDateTime] = field( @@ -927,14 +923,13 @@ class TSLSchemeInformationType: "required": True, }, ) - tsltype: Optional[str] = field( + tsltype: Optional[TSLType] = field( default=None, metadata={ "name": "TSLType", "type": "Element", "namespace": "http://uri.etsi.org/02231/v2#", "required": True, - "min_length": 1, }, ) scheme_operator_name: Optional[SchemeOperatorName] = field( @@ -991,7 +986,7 @@ class TSLSchemeInformationType: "namespace": "http://uri.etsi.org/02231/v2#", }, ) - scheme_territory: Optional[str] = field( + scheme_territory: Optional[SchemeTerritory] = field( default=None, metadata={ "name": "SchemeTerritory", diff --git a/pyhanko/generated/etsi/xades.py b/pyhanko/generated/etsi/xades.py index 524c3b1e..aa1a6d16 100644 --- a/pyhanko/generated/etsi/xades.py +++ b/pyhanko/generated/etsi/xades.py @@ -1,12 +1,13 @@ from dataclasses import dataclass, field from enum import Enum -from typing import Dict, Optional, Tuple +from typing import Any, Dict, Optional, Tuple from xsdata.models.datatype import XmlDateTime from ..w3c.xmldsig_core import ( CanonicalizationMethod, DigestMethod, + DigestValue, Signature, Transforms, X509IssuerSerialType, @@ -356,14 +357,13 @@ class DigestAlgAndValueType: "required": True, }, ) - digest_value: Optional[bytes] = field( + digest_value: Optional[DigestValue] = field( default=None, metadata={ "name": "DigestValue", "type": "Element", "namespace": "http://www.w3.org/2000/09/xmldsig#", "required": True, - "format": "base64", }, ) @@ -504,14 +504,13 @@ class ReferenceInfoType: "required": True, }, ) - digest_value: Optional[bytes] = field( + digest_value: Optional[DigestValue] = field( default=None, metadata={ "name": "DigestValue", "type": "Element", "namespace": "http://www.w3.org/2000/09/xmldsig#", "required": True, - "format": "base64", }, ) id: Optional[str] = field( @@ -1084,6 +1083,12 @@ class Meta: @dataclass(frozen=True) class OtherTimeStampType(GenericTimeStampType): + include: Any = field( + init=False, + metadata={ + "type": "Ignore", + }, + ) reference_info: Tuple[ReferenceInfo, ...] = field( default_factory=tuple, metadata={ @@ -1123,7 +1128,12 @@ class Meta: @dataclass(frozen=True) class XAdESTimeStampType(GenericTimeStampType): - pass + reference_info: Any = field( + init=False, + metadata={ + "type": "Ignore", + }, + ) @dataclass(frozen=True) diff --git a/pyhanko/generated/w3c/xmldsig_core.py b/pyhanko/generated/w3c/xmldsig_core.py index d401aa81..5d46418b 100644 --- a/pyhanko/generated/w3c/xmldsig_core.py +++ b/pyhanko/generated/w3c/xmldsig_core.py @@ -610,14 +610,13 @@ class ReferenceType: "required": True, }, ) - digest_value: Optional[bytes] = field( + digest_value: Optional[DigestValue] = field( default=None, metadata={ "name": "DigestValue", "type": "Element", "namespace": "http://www.w3.org/2000/09/xmldsig#", "required": True, - "format": "base64", }, ) id: Optional[str] = field( @@ -699,7 +698,7 @@ class KeyInfoType: "choices": ( { "name": "KeyName", - "type": str, + "type": KeyName, "namespace": "http://www.w3.org/2000/09/xmldsig#", }, { @@ -729,7 +728,7 @@ class KeyInfoType: }, { "name": "MgmtData", - "type": str, + "type": MgmtData, "namespace": "http://www.w3.org/2000/09/xmldsig#", }, ), diff --git a/pyhanko/sign/validation/report/tools.py b/pyhanko/sign/validation/report/tools.py index 4d117abb..28d4985d 100644 --- a/pyhanko/sign/validation/report/tools.py +++ b/pyhanko/sign/validation/report/tools.py @@ -94,7 +94,9 @@ def _summarise_attrs( digest_method=xmldsig_core.DigestMethod( _digest_algo_uri(hash_algo), ), - digest_value=cert_id['cert_hash'].native, + digest_value=xmldsig_core.DigestValue( + cert_id['cert_hash'].native + ), x509_issuer_serial=( cert_id['issuer_serial'].dump() if cert_id['issuer_serial'] @@ -275,7 +277,7 @@ def _generate_report( digest_method=xmldsig_core.DigestMethod( _digest_algo_uri(api_status.md_algorithm) ), - digest_value=dtbsr_digest, + digest_value=xmldsig_core.DigestValue(dtbsr_digest), ) sig_id = ts_11910202.SignatureIdentifierType( signature_value=xmldsig_core.SignatureValue( @@ -322,7 +324,9 @@ def _generate_report( digest_method=xmldsig_core.DigestMethod( _digest_algo_uri(api_status.md_algorithm) ), - digest_value=embedded_sig.compute_digest(), + digest_value=xmldsig_core.DigestValue( + embedded_sig.compute_digest() + ), ), ), signature_attributes=_summarise_attrs(embedded_sig, api_status), @@ -389,6 +393,6 @@ def generate_report( from xsdata.formats.dataclass.serializers import XmlSerializer from xsdata.formats.dataclass.serializers.config import SerializerConfig - config = SerializerConfig(pretty_print=True) - ser = XmlSerializer(config).render(report, ns_map=NAMESPACES) + config = SerializerConfig(indent=" ") + ser = XmlSerializer(config=config).render(report, ns_map=NAMESPACES) return ser diff --git a/pyhanko_tests/test_ades_validation_report.py b/pyhanko_tests/test_ades_validation_report.py index b9f3f6b6..154c0f7a 100644 --- a/pyhanko_tests/test_ades_validation_report.py +++ b/pyhanko_tests/test_ades_validation_report.py @@ -1,4 +1,3 @@ -import sys from io import BytesIO import pytest diff --git a/pyproject.toml b/pyproject.toml index c8dba635..3b716b6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,7 @@ image-support = [ ] pkcs11 = ["python-pkcs11~=0.7.0"] async-http = ["aiohttp~=3.9.0"] -etsi = ["xsdata>=23.8,<25.0"] +etsi = ["xsdata>=24.4,<25.0"] testing-basic = [ "pytest>=6.1.1", "requests-mock>=1.8.0",