Skip to content

Commit

Permalink
Update xsdata to 24.4
Browse files Browse the repository at this point in the history
 - New major version.
 - All breaking changes only affect pyHanko internals (generated code,
   serialiser setup)
  • Loading branch information
MatthiasValvekens committed Apr 26, 2024
1 parent 95abeef commit f0815f8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
5 changes: 4 additions & 1 deletion external-schemata/genxml.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash

pip install 'ruff>=0.3.0'

xsdata generate \
--config ./external-schemata/.xsdata.xml \
-p pyhanko.generated \
--recursive \
./external-schemata/xsd/

isort --profile black --line-length 80 pyhanko/generated
black -S --line-length 80 pyhanko/generated
black -S --line-length 80 pyhanko/generated
14 changes: 8 additions & 6 deletions pyhanko/generated/etsi/ts_11910202.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -186,7 +191,6 @@ class VOReferenceType:
metadata={
"name": "VOReference",
"type": "Attribute",
"required": True,
"tokens": True,
},
)
Expand Down Expand Up @@ -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",
},
)

Expand All @@ -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",
},
)

Expand Down
17 changes: 6 additions & 11 deletions pyhanko/generated/etsi/ts_119612.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 16 additions & 6 deletions pyhanko/generated/etsi/xades.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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",
},
)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pyhanko/generated/w3c/xmldsig_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -699,7 +698,7 @@ class KeyInfoType:
"choices": (
{
"name": "KeyName",
"type": str,
"type": KeyName,
"namespace": "http://www.w3.org/2000/09/xmldsig#",
},
{
Expand Down Expand Up @@ -729,7 +728,7 @@ class KeyInfoType:
},
{
"name": "MgmtData",
"type": str,
"type": MgmtData,
"namespace": "http://www.w3.org/2000/09/xmldsig#",
},
),
Expand Down
14 changes: 9 additions & 5 deletions pyhanko/sign/validation/report/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion pyhanko_tests/test_ades_validation_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from io import BytesIO

import pytest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f0815f8

Please sign in to comment.