
     h                         d dl mZ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 	 d dlZn# e$ rZ ed          edZ[ww xY w G d d	e	          ZdS )
    )OptionalUnion)cmstsp)LazySession)TimeStamperTimestampRequestError)set_tsp_headersNz?Install pyHanko with the [async_http] optional dependency groupc                        e Zd Z	 	 	 	 ddeej        ef         deej                 f fdZ	de
fdZdej        fd	Zdej        f fd
Zdej        dej        fdZ xZS )AIOHttpTimeStamperF   Nsessionauthc                     |r$|                     d          st          d          || _        || _        || _        || _        || _        t                                                       dS )a  
        Initialise the timestamp client.

        :param url:
            URL where the server listens for timestamp requests.
        :param https:
            Enforce HTTPS.
        :param timeout:
            Timeout (in seconds)
        :param auth:
            `aiohttp.BasicAuth` object with authentication credentials.
        :param headers:
            Other headers to include.
        zhttps:zTimestamp URL is not HTTPS.N)	
startswith
ValueErrorurltimeoutr   headers_sessionsuper__init__)selfr   r   httpsr   r   r   	__class__s          b/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/sign/timestamps/aiohttp_client.pyr   zAIOHttpTimeStamper.__init__   sn    .  	<11 	<:;;;	    returnc                 2   K   t          | j        pi           S )z
        Format the HTTP request headers.
        Subclasses can override this to perform their own header generation
        logic.

        :return:
            Header dictionary.
        )r
   r   )r   s    r   async_request_headersz(AIOHttpTimeStamper.async_request_headers2   s       t|1r222r   c                 v   K   | j         }t          |t                    r|                                 d {V S |S N)r   
isinstancer   get_session)r   r   s     r   r$   zAIOHttpTimeStamper.get_session=   sH      -g{++ 	 ,,.........Nr   c                 X   K   t                                          ||           d {V S r"   )r   async_timestamp)r   message_digestmd_algorithmr   s      r   r&   z"AIOHttpTimeStamper.async_timestampD   s5       WW,,^\JJJJJJJJJr   reqc                   K   |                                   d {V }t          j        | j                  }|                                  d {V }	 |                    | j        ||                                | j        d|          4 d {V 	 }|	                                 d {V }|j
                            d          }|dk    r-d| d}t          j        |j        |j        ||j
                  	 d d d           d {V  n# 1 d {V swxY w Y   n'# t          j        $ r}	t!          d	          |	d }	~	ww xY wt"          j                            |          S )
N)totalT)r   r   datar   raise_for_statusr   zContent-Typezapplication/timestamp-replyz?Bad content type. Expected application/timestamp-reply,but got .)messager   z(Error while contacting timestamp service)r$   aiohttpClientTimeoutr   r    postr   dumpr   readr   getContentTypeErrorrequest_infohistoryClientErrorr	   r   TimeStampRespload)
r   r)   r   
cl_timeoutr   responseresponse_datactmsges
             r   async_request_tsa_responsez-AIOHttpTimeStamper.async_request_tsa_responseI   s@      ((*********>>>
2244444444	||HXXZZY!%" $           &.mmoo 5 5 5 5 5 5%)).99666E?AE E E  "2 - ( # ( 0	                              * " 	 	 	': 	  %%m444s=   =D A(D9D 
DD DD E,D<<E)Fr   NN)__name__
__module____qualname__r   r0   ClientSessionr   r   	BasicAuthr   dictr    r$   r   ContentInfor&   r   TimeStampReqr:   rB   __classcell__)r   s   @r   r   r      s       
 ,0  w,k9: w()     @	3T 	3 	3 	3 	37#8    K	K K K K K K
!5#!5		!5 !5 !5 !5 !5 !5 !5 !5r   r   )typingr   r   
asn1cryptor   r   4pyhanko_certvalidator.fetchers.aiohttp_fetchers.utilr   pyhanko.sign.timestampsr   r	   $pyhanko.sign.timestamps.common_utilsr
   r0   ImportError_er    r   r   <module>rT      s    " " " " " " " "         L L L L L L F F F F F F F F @ @ @ @ @ @NNNN   
+I Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y5s   + A<A