§
    ¥”jü  ã                   óv   — d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ dgZ G d	„ d¦  «        ZdS )
zï
Module to handle the timestamping functionality in pyHanko.

Many PDF signature profiles require trusted timestamp tokens.
The tools in this module allow pyHanko to obtain such tokens from
:rfc:`3161`-compliant time stamping
authorities.
é    N)ÚalgosÚcmsÚtsp)ÚCertificateValidator)ÚSimpleCertificateStoreé   )Údummy_digestÚextract_ts_certsÚ	get_nonceÚhandle_tsp_responseÚTimeStamperc                   ó‚   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zde	j
        fd	„Zd
ej        dej        fd„Zde	j
        fd„ZdS )r   z‘
    .. versionchanged:: 0.9.0
        Made API more asyncio-friendly _(breaking change)_

    Class to make :rfc:`3161` timestamp requests.
    Tc                 óV   — i | _         i | _        t          ¦   «         | _        || _        d S ©N)Ú_dummy_response_cacheÚ_certsr   Úcert_registryÚinclude_nonce)Úselfr   s     új/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/pyhanko/sign/timestamps/api.pyÚ__init__zTimeStamper.__init__"   s-   € Ø%'ˆÔ"ØˆŒÝ3Ñ5Ô5ˆÔØ*ˆÔÐÐó    c                 óê   — dt          j        t          j        d|i¦  «        |dœ¦  «        ddœ}| j        r&t          ¦   «         }t          j        |¦  «        |d<   nd}|t          j        |¦  «        fS )a&  
        Format the body of an :rfc:`3161` request as a CMS object.
        Subclasses with more specific needs may want to override this.

        :param message_digest:
            Message digest to which the timestamp will apply.
        :param md_algorithm:
            Message digest algorithm to use.

            .. note::
                As per :rfc:`8933`, ``md_algorithm`` should also be the
                algorithm used to compute ``message_digest``.
        :return:
            An :class:`.asn1crypto.tsp.TimeStampReq` object.
        r   Ú	algorithm)Úhash_algorithmÚhashed_messageT)ÚversionÚmessage_imprintÚcert_reqÚnonceN)	r   ÚMessageImprintr   ÚDigestAlgorithmr   r   r   ÚIntegerÚTimeStampReq)r   Úmessage_digestÚmd_algorithmÚreqr    s        r   Úrequest_cmszTimeStamper.request_cms(   s•   € ð" Ý"Ô1å&+Ô&;Ø$ lÐ3ñ'ô 'ð '5ð	ð ñ ô  ð ð
ð 
ˆð Ôð 	Ý‘K”KˆEÝœ; uÑ-Ô-ˆC�‰LˆLàˆEØ•cÔ& sÑ+Ô+Ð+Ð+r   c                óà   ‡ ‡K  — ‰                       ¦   «         ƒ d{V —† ˆ ˆfd„}t          |‰ j                             ¦   «         ¦  «        }t	          j        |¦  «        D ]}|ƒ d{V —†W V — ŒdS )a+  
        Produce validation paths for the certificates gathered by this
        :class:`.TimeStamper`.

        This is internal API.

        :param validation_context:
            The validation context to apply.
        :return:
            An asynchronous generator of validation paths.
        Nc                 óx   •— t          | ‰j        ‰¬¦  «        }|                     t          ¦   «         dh¦  «        S )N)Úintermediate_certsÚvalidation_contextÚtime_stamping)r   r   Úasync_validate_usageÚset)ÚcertÚ	validatorr   r,   s     €€r   Ú_validation_jobz5TimeStamper.validation_paths.<locals>._validation_jobZ   sB   ø€ Ý,ØØ#'Ô#5Ø#5ðñ ô ˆIð
 ×1Ò1µ#±%´%¸/Ð9JÑKÔKÐKr   )Ú_ensure_dummyÚmapr   ÚvaluesÚasyncioÚas_completed)r   r,   r2   ÚjobsÚjobs   ``   r   Úvalidation_pathszTimeStamper.validation_pathsL   s®   øøè è € ð × Ò Ñ"Ô"Ð"Ð"Ð"Ð"Ð"Ð"Ð"ð	Lð 	Lð 	Lð 	Lð 	Lð 	Lõ �? D¤K×$6Ò$6Ñ$8Ô$8Ñ9Ô9ˆåÔ'¨Ñ-Ô-ð 	ð 	ˆCØ�)�)�)�)�)�)ˆOˆOˆOˆOˆOð	ð 	r   c                 óh   — || j         |<   t          || j        ¦  «        D ]}|| j        |j        <   Œd S r   )r   r
   r   r   Úissuer_serial)r   r&   Údummyr0   s       r   Ú_register_dummyzTimeStamper._register_dummyg   sG   € Ø38ˆÔ" <Ñ0Ý$ U¨DÔ,>Ñ?Ô?ð 	3ð 	3ˆDØ.2ˆDŒK˜Ô*Ñ+Ð+ð	3ð 	3r   c              ƒ   ó^   K  — | j         s#ddlm} |                      |¦  «        ƒ d {V —† d S d S )Nr   )Ú
DEFAULT_MD)r   Úpyhanko.signr@   Úasync_dummy_response)r   r@   s     r   r3   zTimeStamper._ensure_dummyl   sY   è è € àÔ)ð 	8Ø/Ð/Ð/Ð/Ð/Ð/à×+Ò+¨JÑ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7ð	8ð 	8r   Úreturnc              ƒ   óÄ   K  — 	 | j         |         S # t          $ r, |                      t          |¦  «        |¦  «        ƒ d{V —†}Y nw xY w|                      ||¦  «         |S )a9  
        Return a dummy response for use in CMS object size estimation.

        For every new ``md_algorithm`` passed in, this method will call
        the :meth:`timestamp` method exactly once, with a dummy digest.
        The resulting object will be cached and reused for future invocations
        of :meth:`dummy_response` with the same ``md_algorithm`` value.

        :param md_algorithm:
            Message digest algorithm to use.
        :return:
            A timestamp token, encoded as an
            :class:`.asn1crypto.cms.ContentInfo` object.
        N)r   ÚKeyErrorÚasync_timestampr	   r>   )r   r&   r=   s      r   rB   z TimeStamper.async_dummy_responses   s•   è è € ð$	ØÔ-¨lÔ;Ð;øÝð 	ð 	ð 	Ø×.Ò.Ý˜\Ñ*Ô*¨Lñô ð ð ð ð ð ð ˆEˆEˆEð	øøøð 	×Ò˜\¨5Ñ1Ô1Ð1Øˆs   „ ‘3AÁAr'   c              ƒ   ó   K  — t           ‚)aF  
        Submit the specified timestamp request to the server.

        :param req:
            Request body to submit.
        :return:
            A timestamp response from the server.
        :raises IOError:
            Raised in case of an I/O issue in the communication with the
            timestamping server.
        )ÚNotImplementedError)r   r'   s     r   Úasync_request_tsa_responsez&TimeStamper.async_request_tsa_responseŽ   s   è è € õ "Ð!r   c              ƒ   óŽ   K  — |                       ||¦  «        \  }}|                      |¦  «        ƒ d{V —†}t          ||¦  «        S )a+  
        Request a timestamp for the given message digest.

        :param message_digest:
            Message digest to which the timestamp will apply.
        :param md_algorithm:
            Message digest algorithm to use.

            .. note::
                As per :rfc:`8933`, ``md_algorithm`` should also be the
                algorithm used to compute ``message_digest``.
        :return:
            A timestamp token, encoded as an
            :class:`.asn1crypto.cms.ContentInfo` object.
        :raises IOError:
            Raised in case of an I/O issue in the communication with the
            timestamping server.
        :raises TimestampRequestError:
            Raised if the timestamp server did not return a success response,
            or if the server's response is invalid.
        N)r(   rI   r   )r   r%   r&   r    r'   Úress         r   rF   zTimeStamper.async_timestampž   sV   è è € ð2 ×%Ò% n°lÑCÔC‰
ˆˆsØ×3Ò3°CÑ8Ô8Ð8Ð8Ð8Ð8Ð8Ð8ˆÝ" 3¨Ñ.Ô.Ð.r   N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r:   r>   r3   r   ÚContentInforB   r   r$   ÚTimeStampResprI   rF   © r   r   r   r      sÔ   € € € € € ðð ð+ð +ð +ð +ð",ð ",ð ",ðHð ð ð63ð 3ð 3ð
8ð 8ð 8ð¸#¼/ð ð ð ð ð6"ØÔ#ð"à	Ô	ð"ð "ð "ð "ð /à	Œð/ð /ð /ð /ð /ð /r   )rO   r6   Ú
asn1cryptor   r   r   Úpyhanko_certvalidatorr   Úpyhanko_certvalidator.registryr   Úcommon_utilsr	   r
   r   r   Ú__all__r   rR   r   r   ú<module>rX      sÝ   ððð ð €€€à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø AÐ AÐ AÐ AÐ AÐ Aðð ð ð ð ð ð ð ð ð ð ð ð ˆ/€ð_/ð _/ð _/ð _/ð _/ñ _/ô _/ð _/ð _/ð _/r   