
    Wwg<3                        d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ ddlmZmZ ddlmZmZmZmZ ddlm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- g dZ. ede,      Z/e,dddddfdej`                  dee1   dee
   dee2   dee&   f
dZ3dddejh                  dfdee1eejj                  ejl                  f   dej`                  dee
   dee
   dee&   de-fdZ7	 	 	 	 	 d(de!dee
   dee
   d ee   dee&   d!e8de*fd"Z9	 	 	 d)de!dee
   d ee   d!e8de(f
d#Z:dd$dddejh                  fde!de
fd%Z;	 	 	 	 	 	 d*de!d&ed ee   dee&   d!e8de*fd'Z<y)+    N)IOOptionalTypeVarUnion)cms)ValidationContext)misc   )
DiffPolicy   )VRIDocumentSecurityStoreasync_add_validation_infocollect_validation_info)SigSeedValueValidationErrorValidationInfoReadingError)async_validate_cms_signatureasync_validate_detached_cms)RevocationInfoValidationTypeapply_adobe_revocation_info async_validate_pdf_ltv_signatureget_timestamp_chain)
DocMDPInfoEmbeddedPdfSignatureasync_validate_pdf_signatureasync_validate_pdf_timestampread_certification_data)KeyUsageConstraints)DocumentTimestampStatusModificationInfoPdfSignatureStatusSignatureCoverageLevelSignatureStatusStandardCMSSignatureStatus)r"   r!   r   r$   r    r   r   r   r   r   r   r   r   validate_pdf_signaturer   validate_cms_signaturer   validate_detached_cmsr   validate_pdf_timestampr   validate_pdf_ltv_signaturer   r   add_validation_info
StatusType)boundFsigned_data
raw_digestvalidation_contextstatus_kwargskey_usage_settingsc                     t        j                  dt               t        | |||||      }t	        j
                  |      S )a  
    .. deprecated:: 0.9.0
        Use :func:`~.generic_cms.async_validate_cms_signature` instead.

    .. versionchanged:: 0.7.0
        Now handles both detached and enveloping signatures.

    .. versionchanged:: 0.17.0
        The ``encap_data_invalid`` parameter is ignored.

    Validate a CMS signature (i.e. a ``SignedData`` object).

    :param signed_data:
        The :class:`.asn1crypto.cms.SignedData` object to validate.
    :param status_cls:
        Status class to use for the validation result.
    :param raw_digest:
        Raw digest, computed from context.
    :param validation_context:
        Validation context to validate the signer's certificate.
    :param status_kwargs:
        Other keyword arguments to pass to the ``status_class`` when reporting
        validation results.
    :param key_usage_settings:
        A :class:`.KeyUsageConstraints` object specifying which key usages
        must or must not be present in the signer's certificate.
    :param encap_data_invalid:
        As of version ``0.17.0``, this parameter is ignored.
    :return:
        A :class:`.SignatureStatus` object (or an instance of a proper subclass)
    zR'validate_cms_signature' is deprecated, use 'async_validate_cms_signature' instead)r-   
status_clsr.   r/   r0   r1   )warningswarnDeprecationWarningr   asynciorun)r-   r3   r.   r/   r0   r1   encap_data_invalidcoros           W/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/validation/__init__.pyr&   r&   N   sH    R MM	1 (-#-D ;;t    
input_datasigner_validation_contextts_validation_contextreturnc           	          t        j                  dt               t        | ||||||      }t	        j
                  |      S )a  
    .. deprecated:: 0.9.0
        Use :func:`.generic_cms.async_validate_detached_cms` instead.

    .. versionadded: 0.7.0

    Validate a detached CMS signature.

    :param input_data:
        The input data to sign. This can be either a :class:`bytes` object,
        a file-like object or a :class:`cms.ContentInfo` /
        :class:`cms.EncapsulatedContentInfo` object.

        If a CMS content info object is passed in, the `content` field
        will be extracted.
    :param signed_data:
        The :class:`cms.SignedData` object containing the signature to verify.
    :param signer_validation_context:
        Validation context to use to verify the signer certificate's trust.
    :param ts_validation_context:
        Validation context to use to verify the TSA certificate's trust, if
        a timestamp token is present.
        By default, the same validation context as that of the signer is used.
    :param key_usage_settings:
        Key usage parameters for the signer.
    :param chunk_size:
        Chunk size to use when consuming input data.
    :param max_read:
        Maximal number of bytes to read from the input stream.
    :return:
        A description of the signature's status.
    zP'validate_detached_cms' is deprecated, use 'async_validate_detached_cms' instead)r=   r-   r>   r?   r1   
chunk_sizemax_read)r4   r5   r6   r   r7   r8   )r=   r-   r>   r?   r1   rB   rC   r:   s           r;   r'   r'      sK    T MM	0 '";3-D ;;tr<   embedded_sigdiff_policy	skip_diffc                 N    t        | |||||      }t        j                  |      S )a  
    .. versionchanged:: 0.9.0
        Wrapper around :func:`~.pdf_embedded.async_validate_pdf_signature`.

    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 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.
    :return:
        The status of the PDF signature in question.
    )rD   r>   r?   rE   r1   rF   )r   r7   r8   )rD   r>   r?   rE   r1   rF   r:   s          r;   r%   r%      s2    D (!";3-D ;;tr<   c                 J    t        | |||      }t        j                  |      S )a  
    .. versionchanged:: 0.9.0
        Wrapper around :func:`~.pdf_embedded.async_validate_pdf_timestamp`.

    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.
    )rD   r/   rE   rF   )r   r7   r8   )rD   r/   rE   rF   r:   s        r;   r(   r(      s+    4 (!-	D ;;tr<   Tc           
      R    t        | |||||||      }t        j                  |      S )al  
    .. versionchanged:: 0.9.0
        Wrapper around :func:`~.dss.async_add_validation_info`

    Add validation info (CRLs, OCSP responses, extra certificates) for a
    signature to the DSS of a document in an incremental update.

    :param embedded_sig:
        The signature for which the revocation information needs to be
        collected.
    :param validation_context:
        The validation context to use.
    :param skip_timestamp:
        If ``True``, do not attempt to validate the timestamp attached to
        the signature, if one is present.
    :param add_vri_entry:
        Add a ``/VRI`` entry for this signature to the document security store.
        Default is ``True``.
    :param output:
        Write the output to the specified output stream.
        If ``None``, write to a new :class:`.BytesIO` object.
        Default is ``None``.
    :param in_place:
        Sign the original input stream in-place.
        This parameter overrides ``output``.
    :param chunk_size:
        Chunk size parameter to use when copying output to a new stream
        (irrelevant if ``in_place`` is ``True``).
    :param force_write:
        Force a new revision to be written, even if not necessary (i.e.
        when all data in the validation context is already present in the DSS).
    :return:
        The (file-like) output object to which the result was written.
    )rD   r/   skip_timestampadd_vri_entryoutputin_placerB   force_write)r   r7   r8   )	rD   r/   rJ   rK   rM   rL   rN   rB   r:   s	            r;   r*   r*     s8    Z %!-%#	D ;;tr<   validation_typec           
      R    t        | |||||||      }t        j                  |      S )a  
    .. versionchanged:: 0.9.0
        Wrapper around :func:`async_validate_pdf_ltv_signature`.

    Validate a PDF LTV signature according to a particular profile.

    :param embedded_sig:
        Embedded signature to evaluate.
    :param validation_type:
        Validation profile to use.
    :param validation_context_kwargs:
        Keyword args to instantiate
        :class:`.pyhanko_certvalidator.ValidationContext` objects needed over
        the course of the validation.
    :param bootstrap_validation_context:
        Validation context used to validate the current timestamp.
    :param force_revinfo:
        Require all certificates encountered to have some form of live
        revocation checking provisions.
    :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.
    :return:
        The status of the signature.
    )rD   rO   validation_context_kwargsbootstrap_validation_contextforce_revinforE   r1   rF   )r   r7   r8   )	rD   rO   rQ   rR   rS   rE   r1   rF   r:   s	            r;   r)   r)   N  s8    T ,!'";%A#-	D ;;tr<   )NNNNF)NNF)NNFNNF)=r7   r4   typingr   r   r   r   
asn1cryptor   pyhanko_certvalidatorr   pyhanko.pdf_utilsr	   diff_analysisr   dssr   r   r   r   errorsr   r   generic_cmsr   r   ltvr   r   r   r   pdf_embeddedr   r   r   r   r   settingsr   statusr   r    r!   r"   r#   r$   __all__r+   
SignedDatabytesdictr&   DEFAULT_CHUNK_SIZEContentInfoEncapsulatedContentInfor'   boolr%   r(   r*   r)    r<   r;   <module>ri      s     / /  3 " &  L   * : \9
 "&6:$(8<77 7 !!23	7
 D>7 !!457z >B9=8<&&9eR#2M2MMN99  ((9:9 $$56	9
 !!459  9| >B9=(,8<*&*'(9:* $$56* *%	*
 !!45* * *^ 7;(,	 &  !23  *%  	 
  L &&7&7)7z #!%(,8<4&414 *%4 !!454 4 4r<   