From a5dcf644a98256063f520250f86df2b4c9d2ec29 Mon Sep 17 00:00:00 2001 From: Matthias Valvekens Date: Tue, 24 Oct 2023 01:09:30 +0200 Subject: [PATCH] Correct definition of PdfMacIntegrityInfo --- pyhanko/pdf_utils/crypt/_iso32004_asn1.py | 2 +- pyhanko/pdf_utils/crypt/pdfmac.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyhanko/pdf_utils/crypt/_iso32004_asn1.py b/pyhanko/pdf_utils/crypt/_iso32004_asn1.py index b7c94abc..d861f913 100644 --- a/pyhanko/pdf_utils/crypt/_iso32004_asn1.py +++ b/pyhanko/pdf_utils/crypt/_iso32004_asn1.py @@ -12,7 +12,7 @@ class PdfMacIntegrityInfo(Sequence): _fields = [ - ('version', Integer, {'default': 0}), + ('version', Integer), ('data_digest', OctetString), ('signature_digest', OctetString, {'implicit': 0, 'optional': True}), ] diff --git a/pyhanko/pdf_utils/crypt/pdfmac.py b/pyhanko/pdf_utils/crypt/pdfmac.py index 63c0fc89..4dec38c0 100644 --- a/pyhanko/pdf_utils/crypt/pdfmac.py +++ b/pyhanko/pdf_utils/crypt/pdfmac.py @@ -1,7 +1,7 @@ import os import secrets from hmac import compare_digest -from typing import FrozenSet, Optional, Tuple, Type +from typing import Any, Dict, FrozenSet, Optional, Tuple, Type from asn1crypto import algos, cms, core from asn1crypto.core import VOID @@ -210,9 +210,10 @@ def _get_mac_keying_info( def _format_message( self, document_digest: bytes, signature_digest: Optional[bytes] ) -> Tuple[bytes, bytes]: - message_kwargs = {'data_digest': document_digest} + message_kwargs: Dict[str, Any] = {'data_digest': document_digest} if signature_digest is not None: message_kwargs['signature_digest'] = signature_digest + message_kwargs['version'] = 0 message = PdfMacIntegrityInfo(message_kwargs) message_bytes = message.dump()