
    Wwg                        d dl Z d dlZd dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZmZmZmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$ d dl%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z;m<Z< ddl=m>Z> g dZ? e j                  eA      ZBdeej                     fdZDdee    fdZEdej                  deFfdZG G d d      ZH edddg      ZI	 dedeeI   fd ZJd!eHfd"ZKd#eHd$ed%eLfd&ZMd' ZN	 	 	 	 	 	 	 d2d#eHd(ee   d)ee   d*ee   d+ee   d,ee8   d-eLd.ee>   de;fd/ZO	 	 	 d3d#eHd0ee   d+ee   d-eLde:f
d1ZPy)4    N)
namedtuple)datetime)ListOptionalUnion)cmsx509)ValidationContext)ValidationPath)genericmisc)pdf_name)PdfFileReaderprocess_data_at_eof)DEFAULT_DIFF_POLICY
DiffPolicy
DiffResultModificationLevelSuspiciousModification)FieldMDPSpecMDPPermSeedLockDocumentSigSeedSubFilterSigSeedValFlagsSigSeedValueSpec)SignedDataCertsUnacceptableSignerErrorbyte_range_digestextract_signer_info   )SignatureValidationErrorSigSeedValueValidationErrorValidationInfoReadingError)cms_basic_validationcollect_signer_attr_statuscollect_timing_infocompute_signature_tst_digestextract_certs_for_validationextract_self_reported_tsextract_tst_datavalidate_tst_signed_data)KeyUsageConstraints)DocumentTimestampStatusPdfSignatureStatusSignatureCoverageLevel)CMSAlgorithmUsagePolicy)EmbeddedPdfSignature
DocMDPInforead_certification_dataasync_validate_pdf_signatureasync_validate_pdf_timestampreport_seed_value_validationextract_contentsreturnc                 t    	 | d   }|D ]  }|j                         }|d   |k(  s|c S  y # t         $ r Y y w xY w)Nz
/Referencez/TransformMethod)KeyError
get_object)signature_objmethodsig_refsrefs       [/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/validation/pdf_embedded.py_extract_reference_dictrA   I   sZ     .  nn!"f,J   s   + 	77c                     t        | d      }|y 	 |d   j                  d      }t        |      S # t        t        f$ r}t        d      |d }~ww xY w)N/DocMDP/TransformParams/Pz#Failed to read document permissions)rA   raw_getr   
ValueErrorr:   r!   )r<   r?   	raw_permses       r@   _extract_docmdp_for_sigrJ   W   sd    
!-
;C
{*+33D9	y!!! &1
	s   0 AAA
sig_objectc                 4   	 | j                  dt        j                  j                        }t        |t        j                  t        j                  f      st        j                  d      |j                  S # t        $ r t        j                  d      w xY w)z
    Internal function to extract the (DER-encoded) signature bytes from a PDF
    signature dictionary.

    :param sig_object:
        A signature dictionary.
    :return:
        The extracted contents as a byte string.
    z	/Contents)decryptz+Could not read /Contents entry in signaturez/Contents must be string-like)rF   r   EncryptedObjAccessRAWr:   r   PdfReadError
isinstanceTextStringObjectByteStringObjectoriginal_bytes)rK   cms_contents     r@   r7   r7   d   s    O ((!;!;!?!? ) 
 g..0H0HI  ?@@%%%  O MNNOs   +A8 8Bc                   h   e Zd ZU dZej
                  ed<   	 ej
                  ed<   	 ej                  ed<   	 de	dej
                  de
fdZdefd	Zedeej                      fd
       Zedeej&                     fd       Zedej&                  fd       Zedej,                  fd       Zed        Zedee   fd       Zedeej                     fd       ZddZdefdZedee    fd       Z!edee"   fd       Z#edee$   fd       Z%de&fdZ'dee&   fdZ(de)fdZ*d Z+de,de-e.e/f   fdZ0y)r1   zA
    Class modelling a signature embedded in a PDF document.
    	sig_fieldrK   signed_datareaderfq_namec                 ,   || _         t        |t        j                        r|j	                         }|| _        |j                  d      }|j	                         x| _        }t        |t        j                        sJ 	 |j                  d      | _	        t        |      x| _        }t        j                   j#                  |      }|d   }|| _        t'        |      | _        d | _        | j(                  d   }	|	d   j,                  j/                         | _        |d   }
|
d   j,                  }|d	k(  r| j0                  | _        n.|d
k(  r)|
d   j4                  d   }|d   d   j,                  | _        | j                   j6                  j9                  |j:                        | _        d | _        d | _         d | _!        d | _"        d | _#        dx| _$        | _%        d | _&        d | _'        d| _(        || _)        y # t        $ r t        j                  d      w xY w)Nz/Vz
/ByteRangez,Could not read /ByteRange entry in signaturecontentdigest_algorithm	algorithmencap_content_infocontent_typedatatst_infomessage_imprinthash_algorithmF)*rY   rQ   r   IndirectObjectr;   rW   rF   rK   DictionaryObject
byte_ranger:   r   rP   r7   pkcs7_contentr   ContentInfoloadrX   r   signer_info_sd_cert_infonativelowermd_algorithmexternal_md_algorithmparsedxrefsget_last_change	referencesigned_revisioncoverageexternal_digest	total_len_docmdp	_fieldmdp_docmdp_queried_fieldmdp_queriedtst_signature_digestdiff_result_integrity_checkedrZ   )selfrY   rW   rZ   sig_object_refrK   rU   messagerX   digest_algoecir`   mis                r@   __init__zEmbeddedPdfSignature.__init__   s    i!7!78!,,.I""**40'5'@'@'BB**g&>&>???	(00>DO
 ,<J+GG[//&&{3i(+6.{;8< &&'9:'4;;AAC./>*116!)-):):D&Z' Y&&'89B)+,<)=*f &  ${{00@@$$ 
 04(,*.158==t559!"'w  	##> 	s   >G4 4Hr8   c                 f    | j                   t        | j                        | _         | j                   S )N)rl   r(   rX   r   s    r@   _init_cert_infoz$EmbeddedPdfSignature._init_cert_info   s-    %!=d>N>N!OD!!!    c                 H    t        | j                         j                        S )z2
        Embedded attribute certificates.
        )listr   attribute_certsr   s    r@   embedded_attr_certsz(EmbeddedPdfSignature.embedded_attr_certs   s    
 D((*::;;r   c                 H    t        | j                         j                        S )zQ
        Embedded X.509 certificates, excluding than that of the signer.
        )r   r   other_certsr   s    r@   other_embedded_certsz)EmbeddedPdfSignature.other_embedded_certs   s    
 D((*6677r   c                 6    | j                         j                  S )z,
        Certificate of the signer.
        )r   signer_certr   s    r@   r   z EmbeddedPdfSignature.signer_cert   s    
 ##%111r   c                 L    | j                   j                  dt        d            S )a  
        Returns the type of the embedded signature object.
        For ordinary signatures, this will be ``/Sig``.
        In the case of a document timestamp, ``/DocTimeStamp`` is returned.

        :return:
            A PDF name object describing the type of signature.
        z/Type/Sig)rK   getr   r   s    r@   sig_object_typez$EmbeddedPdfSignature.sig_object_type   s      ""7HV,<==r   c                     | j                   S )zC
        :return:
            Name of the signature field.
        )rZ   r   s    r@   
field_namezEmbeddedPdfSignature.field_name  s     ||r   c                     t        | j                        }||S 	 | j                  d   }t        j                  || j
                  j                        S # t        $ r Y yw xY w)z
        :return:
            The signing time as reported by the signer, if embedded in the
            signature's signed attributes or provided as part of the signature
            object in the PDF document.
        Nz/M)strict)r)   rk   rK   r   parse_pdf_daterY   r   r:   )r   tsst_as_pdf_dates      r@   self_reported_timestampz,EmbeddedPdfSignature.self_reported_timestamp  sg     &d&6&67>I	!__T2N))t{{'9'9   		s   9A 	A! A!c                 ,    t        | j                        S )z
        :return:
            The signed data component of the timestamp token embedded in this
            signature, if present.
        )r*   rk   r   s    r@   attached_timestamp_dataz,EmbeddedPdfSignature.attached_timestamp_data"  s       0 011r   Nc                     | j                          | j                          | j                          | j                         | _        |xs t
        }|s| j                  |      | _        d| _        y)a  
        Compute the various integrity indicators of this signature.

        :param diff_policy:
            Policy to evaluate potential incremental updates that were appended
            to the signed revision of the document.
            Defaults to
            :const:`~pyhanko.sign.diff_analysis.DEFAULT_DIFF_POLICY`.
        :param skip_diff:
            If ``True``, skip the difference analysis step entirely.
        TN)	_enforce_hybrid_xref_policycompute_digestcompute_tst_digestevaluate_signature_coveragerv   r   evaluate_modificationsr~   r   )r   diff_policy	skip_diffs      r@   compute_integrity_infoz+EmbeddedPdfSignature.compute_integrity_info+  sc     	((*! 88:!8%8#::;GD"&r   c                    | j                   st        d      | j                  }| j                  }| j                  }d}|bt        |t              r|j                  nt        j                  }|t        j                  k(  xs |duxr |j                  |j                  kD   }n&|t        j                  k7  r|t        j                  k(  }|||d}|S )a  
        Compile the integrity information for this signature into a dictionary
        that can later be passed to :class:`.PdfSignatureStatus` as kwargs.

        This method is only available after calling
        :meth:`.EmbeddedPdfSignature.compute_integrity_info`.
        zGCall compute_integrity_info() before invokingsummarise_integrity_info()N)rv   	docmdp_okr~   )r   r!   docmdp_levelr~   rv   rQ   r   modification_levelr   OTHERvaluer/   ENTIRE_REVISIONENTIRE_FILE)r   docmdpr~   rv   r   	mod_levelstatus_kwargss          r@   summarise_integrity_infoz-EmbeddedPdfSignature.summarise_integrity_infoD  s     &&*- 
 ""&&==	 " k:6 ..&,,  .444 K$&I9??V\\+II /???
 !$:$F$FFI !"&

 r   c                 j    	 | j                   d   }t        j                  |      S # t        $ r Y y w xY w)Nz/SV)rW   r:   r   from_pdf_object)r   sig_sv_dicts     r@   seed_value_specz$EmbeddedPdfSignature.seed_value_specq  s<    	../K  //<<  		s   & 	22c                     | j                   r| j                  S t        | j                        }|	 | j                  d   }t        |d         }|| _        d| _         |S # t        $ r Y w xY w)av  
        :return:
            The document modification policy required by this signature or
            its Lock dictionary.

            .. warning::
                This does not take into account the DocMDP requirements of
                earlier signatures (if present).

                The specification forbids signing with a more lenient DocMDP
                than the one currently in force, so this should not happen
                in a compliant document.
                That being said, any potential violations will still invalidate
                the earlier signature with the stricter DocMDP policy.

        )r<   z/LockrE   T)r{   ry   rJ   rK   rW   r   r:   )r   r   	lock_dicts      r@   r   z!EmbeddedPdfSignature.docmdp_levely  su    $ <<(tG> NN73	 41 #	  s   A 	A+*A+c                     | j                   r| j                  S t        | j                  d      }d| _         |y	 t	        j
                  |d         }|| _        |S # t        t        f$ r}t        d      |d}~ww xY w)z
        :return:
            Read the field locking policy of this signature, if applicable.
            See also :class:`~.pyhanko.sign.fields.FieldMDPSpec`.
        z	/FieldMDPTNrD   z!Failed to read /FieldMDP settings)	r|   rz   rA   rK   r   r   rG   r:   r!   )r   ref_dictsprI   s       r@   fieldmdpzEmbeddedPdfSignature.fieldmdp  s     !!>>!*4??KH!%	--h7I.JKB
 	 H% 	*3	s   A A;*A66A;c                     | j                   | j                   S t        | j                  j                  | j                  | j
                        \  | _        }|| _         |S )z
        Compute the ``/ByteRange`` digest of this signature.
        The result will be cached.

        :return:
            The digest value.
        )rg   ro   )rw   r   rY   streamrg   rp   rx   r   digests     r@   r   z#EmbeddedPdfSignature.compute_digest  sY     +'''!2KK33"

  &r   c                 n    | j                   | j                   S t        | j                        x| _         }|S )a  
        Compute the digest of the signature needed to validate its timestamp
        token (if present).

        .. warning::
            This computation is only relevant for timestamp tokens embedded
            inside a regular signature.
            If the signature in question is a document timestamp (where the
            entire signature object is a timestamp token), this method
            does not apply.

        :return:
            The digest value, or ``None`` if there is no timestamp token.
        )r}   r'   rk   r   s     r@   r   z'EmbeddedPdfSignature.compute_tst_digest  s@      $$0,,,-I.
 	
!F r   c                    | j                   j                  }| j                   j                  }t        | j                        dk7  s| j                  d   dk7  rt
        j                  S | j                  \  }}}}|j                  dt        j                         t        | j                        dz  dz   }||z   |z   }|j                         |k(  }	|	rt
        j                  S |||z   k(  }
|
st
        j                  S |j                  |       | j                  }	 t        |      }|j                  |      }||k7  rt
        j                   S 	 t'        |dz         D ]4  }|j)                  |      }|j*                  |kD  s$t
        j                   c S  t
        j,                  S # t"        j$                  $ r t
        j                   cY S w xY w)z
        Internal method used to evaluate the coverage level of a signature.

        :return:
            The coverage level of the signature.
           r      r    )rY   rr   r   lenrg   r/   UNCLEARseekosSEEK_ENDrh   tellr   ru   r   get_startxref_for_revisionCONTIGUOUS_BLOCK_FROM_STARTr   rP   rangeget_xref_container_infoend_locationr   )r   
xref_cacher   _len1start2len2embedded_sig_contentsigned_zone_lenfile_covered
contiguous
signed_rev	startxrefexpectedrevision	xref_metas                   r@   r   z0EmbeddedPdfSignature.evaluate_signature_coverage  s    [[&&
 ## t1$(:a(?)111 $4 	Ar{{#  #4#5#56:Q>+(<<{{}7)555 t&:::
)111 	O$))
	F+F3I!<<ZHHH$-III % j1n- 	JH"::8DI%%7-III	J
 &555    	F)EEE	Fs   0F #GGc                 x    | j                   }|j                  r"|j                  j                  rt	        d      y y )NzJSettings do not permit validation of signatures in hybrid-reference files.)rY   r   rr   hybrid_xrefs_presentr!   )r   rY   s     r@   r   z0EmbeddedPdfSignature._enforce_hybrid_xref_policy"  s7    ==V\\>>**  ?=r   r   c                 J   | j                   t        j                  k  rt        d      S | j                   t        j                  k(  r"t        t        j                  t                     S |j                  | j                  | j                  | j                  | j                        S )zY
        Internal method used to evaluate the modification level of a signature.
        z$Nonstandard signature coverage level)field_mdp_specdoc_mdp)rv   r/   r   r   r   r   r   NONEsetreview_filerY   ru   r   r   )r   r   s     r@   r   z+EmbeddedPdfSignature.evaluate_modifications*  s     ==1AAA)6  ]]4@@@/44ce<<&&KK  ==%%	 ' 
 	
r   )NF)1__name__
__module____qualname____doc__r   rf   __annotations__r   
SignedDatar   strr   r   r   propertyr   AttributeCertificateV2r   r	   Certificater   r   
NameObjectr   r   r   r   r   r   r   dictr   r   r   r   r   r   r   bytesr   r   r/   r   r   r   r   r   r   r    r   r@   r1   r1      s     ''' ((( JJ ++J 	JX" "
 <T#*D*D%E < < 8d4+;+;&< 8 8 2T-- 2 2 	>!3!3 	> 	>   ();  & 2#..)A 2 2'2+$ +Z =*:!; = = hw/  > (<0  , &HUO .F6-C F6P
%
	z11	2
r   r1   r2   
permission
author_sigrY   c                 t    	 | j                   d   d   }t        |      }t        ||      S # t        $ r Y yw xY w)z
    Read the certification information for a PDF document, if present.

    :param reader:
        Reader representing the input document.
    :return:
        A :class:`.DocMDPInfo` object containing the relevant data, or ``None``.
    /PermsrC   N)rootr:   rJ   r2   )rY   certification_sigperms      r@   r3   r3   G  sJ    "KK1)< ##45Dd-..	  s   + 	77emb_sigc                  	   | j                   }|y | j                  }|j                  	 |j                  j                  ||       |s|j                  rt        d      | j                  }|j                  |j                  j                         }	 | j                  j                  d   }|j                  d      }	|	|j                  k(  }
||
k7  r!d }t        d ||       d ||
       d      |r9|j                  j$                  }| j&                  }||k7  rt        d	| d
| d      |j(                  }|sy |d   }t+        |      }|t,        j.                  z  r_|j0                  S|j0                  st3        d      |j0                  d   }|+||k7  r&t        d|j4                  d
|j4                  d      |t,        j6                  z  r!|j8                  t:        j=                  d       |t,        j>                  z  r|j@                  t3        d      |t,        jB                  z  r|jD                  | j&                  }|jD                  tF        jH                  k(  r|tJ        jL                  k7  rt        d      |jD                  tF        jN                  k(  r|tJ        jL                  k(  rt        d      | jP                  }|t,        jR                  z  r|jT                  ddl+m,} 	  ||       d}|jT                  |k7  r$t        d|jT                  rdndd|rdndd      |jT                  r9|t*        j\                  k7  r&t        dt*        j\                  j4                  z        |t,        j^                  z  rB|j`                  6| jb                  je                         }||j`                  vrt        d|z        |t,        jf                  z  rR|jh                  xs g }| xs |dgk(  }|jk                  d      }|r|t        d      |s||vrt        d |d!      y y y # t        $ r}t        |      |d }~ww xY w# t        t        j                   t"        f$ r d}
Y w xY w# tZ        $ r d}Y w xY w)"NznThe seed value dictionary requires a trusted timestamp, but none was found, or the timestamp did not validate.r   rC   Fc                     | rdS dS )Nza certificationzan approvalr   )certifys    r@   _typez'_validate_sv_constraints.<locals>._typex  s    ,3(FFr   zPThe seed value dictionary's /MDP entry specifies that this field should contain z signature, but z appears to have been used.zaThe seed value dictionary specified that this certification signature should use the MDP policy 'z', but 'z' was used in the signature.
/SubFilterzPThe signature encodings mandated by the seed value dictionary are not supported.r   z.The seed value dictionary mandates subfilter 'zThe signature's seed value dictionary specifies the /AppearanceFilter entry as mandatory, but this constraint is impossible to validate.zpyHanko does not support legal attestations, but the seed value dictionary mandates that they be restricted to a specific subset.z<Document must be locked, but some changes are still allowed.zGDocument must not be locked, but the DocMDP level is set to NO_CHANGES.)retrieve_adobe_revocation_infoTz2The seed value dict mandates that revocation info  znot zbe added, but it was zfound in the signature.zdThe seed value dict mandates that Adobe-style revocation info be added; this requires subfilter '%s'zKThe selected message digest %s is not allowed by the seed value dictionary..z/Reasonz@The seed value dictionary prohibits giving a reason for signing.zThe reason for signing "z/" is not accepted by the seed value dictionary.)6r   r   certsatisfied_byr   r"   timestamp_requiredrK   seed_signature_typecertification_signaturerY   r   get_value_as_referencecontainer_refr:   r   IndirectObjectExpectedAttributeErrormdp_permr   flagsr   r   	SUBFILTER
subfiltersNotImplementedErrorr   APPEARANCE_FILTER
appearanceloggerwarningLEGAL_ATTESTATIONlegal_attestationsLOCK_DOCUMENTlock_documentr   LOCKr   
NO_CHANGESDO_NOT_LOCKrk   ADD_REV_INFOadd_rev_infopyhanko.sign.validation.ltvr  r#   ADOBE_PKCS7_DETACHEDDIGEST_METHODdigest_methodsro   rn   REASONSreasonsr   )r   validation_pathtimestamp_foundsv_specsigning_certrI   sig_obj
sv_certifypermscert_sig_refwas_certifiedr  sv_mdp_permr   r  selected_sf_strselected_sfmandated_sfrk   r  revinfo_foundselected_mdr(  	must_omitreason_givens                            r@   _validate_sv_constraintsr:  Y  s    %%G&&L||	8LL%%lOD w99)A
 	

   G"".00HHJ
	".5nn.A.A(.KE 77	BL(G,A,AAM &G .--2:->,? @""'"6!7 8--  !55>>K**Gg%1#}HWI 6--  MMEl+O"?3K)))w/A/A/M!!%0 
 )0(:(:1(="{k'A- $$k&7&79  	111



()	
 	111

$
$
0!P
 	
 	---



+&&!!%5%:%::7----N  !!%5%A%AA7----  %%K,,,



*N	"*;7 M =0- "..BF:'BV3	    /DDD->#88>>@  	---

 
 
,**002g444-)+67 
 &&& //'RK37se#3	{{9-1-  \8-,8;  9y '] ' 	8-a0a7	8" '88.I 	"!M	"z * 	"!M	"s;   P* 9Q -
Q. *	Q3P??Q Q+*Q+.Q=<Q=embedded_sigr)  r*  c                     	 t        | ||       d}| j                  du|dS # t        $ r#}t        j                  d|       |}Y d}~8d}~ww xY w)a  
    Internal API function to enforce seed value constraints (if present)
    and report on the result(s).

    :param embedded_sig:
        The embedded signature.
    :param validation_path:
        The validation path for the signer's certificate.
    :param timestamp_found:
        Flag indicating whether a valid timestamp was found or not.
    :return:
        A ``status_kwargs`` dict.
    )r*  NzError in seed value validation.)exc_info)has_seed_valuesseed_value_constraint_error)r:  r"   r  r  r   )r;  r)  r*  sv_errrI   s        r@   r6   r6     sb    & /?	
 
 (77tC'-  ' 81Es   # 	AA

Ac                 h    	 ddl m}  ||       |v }|st        || z        y # t        $ r d}Y w xY w)Nr   )r   F)pyhanko.sign.fieldsr   rG   r!   )subfilter_strpermitted_subfilterserr_msgr   subfilter_oks        r@   _validate_subfilterrG  $  sJ    8'6:NN &w'>??   s   # 11signer_validation_contextts_validation_contextac_validation_contextr   key_usage_settingsr   algorithm_policyc           	        K   | j                   }| j                  dk7  rt        d      |j                  dd      }	t	        |	t
        j                  t
        j                  fd       ||}| j                  ||       | j                         }
t        | j                  || j                                d{   }|
j                  |       d|
vr| j                  }|||
d<   t        j                   |      }t#        | j$                  | j&                  ||
||	       d{   }
|
j                  d
d      }|duxr |j(                  xr |j*                  }t-        | |
d   |      }|
j                  |       |%|j.                  j1                  | j2                         |
j                  t5        | j6                  | j8                  || j                  d          d{          t        di |
S 7 ;7 7 w)a  
    .. versionadded:: 0.9.0

    .. versionchanged: 0.11.0
        Added ``ac_validation_context`` param.


    Validate a PDF signature.

    :param embedded_sig:
        Embedded signature to evaluate.
    :param signer_validation_context:
        Validation context to use to validate the signature's chain of trust.
    :param ts_validation_context:
        Validation context to use to validate the timestamp's chain of trust
        (defaults to ``signer_validation_context``).
    :param ac_validation_context:
        Validation context to use to validate attribute certificates.
        If not supplied, no AC validation will be performed.

        .. note::
            :rfc:`5755` requires attribute authority trust roots to be specified
            explicitly; hence why there's no default.
    :param diff_policy:
        Policy to evaluate potential incremental updates that were appended
        to the signed revision of the document.
        Defaults to
        :const:`~pyhanko.sign.diff_analysis.DEFAULT_DIFF_POLICY`.
    :param key_usage_settings:
        A :class:`.KeyUsageConstraints` object specifying which key usages
        must or must not be present in the signer's certificate.
    :param skip_diff:
        If ``True``, skip the difference analysis step entirely.
    :param algorithm_policy:
        The algorithm usage policy for the signature validation.

        .. warning::
            This is distinct from the algorithm usage policy used for
            certificate validation, but the latter will be used as a fallback
            if this parameter is not specified.

            It is nonetheless recommended to align both policies unless
            there is a clear reason to do otherwise.
    :return:
        The status of the PDF signature in question.
    r   z"Signature object type must be /Sigr  Nz4%s is not a recognized SubFilter type in signatures.r   r   )
raw_digestsigner_reported_dt)rO  validation_contextr   rK  rL  timestamp_validityr)  signed_attrs)sd_attr_certificatesr   rQ  sd_signed_attrsr   )rK   r   r!   r   rG  r   r$  PADESr   r   r&   rk   r   updater   r.   default_usage_constraintsr$   rX   rw   validtrustedr6   certificate_registryregister_multipler   r%   r   r   )r;  rH  rI  rJ  r   rK  r   rL  rK   rC  r   ts_status_kwargsrP  tst_validityr*  	sv_updates                   r@   r4   r4   0  s     r ((J##v-&'KLL NN<6M		.	.0@0F0FG> $ 9''9 (  !99;M0  ..0 
 )*=0)AA)2DM./+EE /  //4#-) M !$$%94@LD P\%7%7PL<P<P  -m$56I #(22DD--	
 (!-!A!A$004(44^D	
 	
 ...W*	
s8   B4G86G17A)G8 G4!B<G8G6G84G86G8rQ  c                   K   | j                   dk7  rt        d      | j                  j                  dd      }t	        |t
        j                  fd       | j                  ||       t        | j                  || j                                d{   }| j                  |d<   | j                  |d<   t        d	i |S 7 -w)
a{  
    .. versionadded:: 0.9.0

    Validate a PDF document timestamp.

    :param embedded_sig:
        Embedded signature to evaluate.
    :param validation_context:
        Validation context to use to validate the timestamp's chain of trust.
    :param diff_policy:
        Policy to evaluate potential incremental updates that were appended
        to the signed revision of the document.
        Defaults to
        :const:`~pyhanko.sign.diff_analysis.DEFAULT_DIFF_POLICY`.
    :param skip_diff:
        If ``True``, skip the difference analysis step entirely.
    :return:
        The status of the PDF timestamp in question.
    z/DocTimeStampz+Signature object type must be /DocTimeStampr  Nz5%s is not a recognized SubFilter type for timestamps.rN  rv   r~   r   )r   r!   rK   r   rG  r   ETSI_RFC3161r   r+   rX   r   rv   r~   r-   )r;  rQ  r   r   rC  r   s         r@   r5   r5     s     4 ##6&9
 	

 !++//dCM		&	&(? ''9 (  3  ##% M !- 5 5M*#/#;#;M- "3]33s   BC B>.C )NNNNNFN)NNF)Qloggingr   collectionsr   r   typingr   r   r   
asn1cryptor   r	   pyhanko_certvalidatorr
   pyhanko_certvalidator.pathr   pyhanko.pdf_utilsr   r   pyhanko.pdf_utils.genericr   pyhanko.pdf_utils.readerr   r   pyhanko.sign.diff_analysisr   r   r   r   r   rB  r   r   r   r   r   r   pyhanko.sign.generalr   r   r   r   errorsr!   r"   r#   generic_cmsr$   r%   r&   r'   r(   r)   r*   r+   settingsr,   statusr-   r.   r/   utilsr0   __all__	getLoggerr   r  rf   rA   rJ   r   r7   r1   r2   r3   r:  boolr6   rG  r4   r5   r   r   r@   <module>ru     s.    	 "  ( (   3 5 + . G    
	 	 	 * 
 + 
		8	$g&&'
hw.? 
&!9!9 &e &8}
 }
@ |\&BC
/M /hz6J /$g!gT&# B	@ >B9=9=(,8<:>x/&x/'(9:x/ $$56x/ $$56	x/
 *%x/ !!45x/ x/ 67x/ x/z 7;(,	34&34 !2334 *%34 	34
 34r   