U
    g                     @   sV   d dl Z d dlmZ d dlmZ ddlmZ ddlmZm	Z	 dgZ
G dd deZdS )	    N)tsp	to_thread   )TimeStamper)TimestampRequestErrorset_tsp_headersHTTPTimeStamperc                       sD   e Zd ZdZd fdd	Zeddd	Zejej	d
ddZ
  ZS )r	   z/
    Standard HTTP-based timestamp client.
    F   Nc                    s<   |r| dstd|| _|| _|| _|| _t   dS )ax  
        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:
            Value of HTTP ``Authorization`` header
        :param headers:
            Other headers to include.
        zhttps:zTimestamp URL is not HTTPS.N)
startswith
ValueErrorurltimeoutauthheaderssuper__init__)selfr   httpsr   r   r   	__class__ K/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/sign/timestamps/requests_client.pyr      s    zHTTPTimeStamper.__init__)returnc                 C   s   t | jp
i S )zc
        Format the HTTP request headers.

        :return:
            Header dictionary.
        )r   r   )r   r   r   r   request_headers'   s    zHTTPTimeStamper.request_headers)reqr   c                    s     fdd}t |I d H }|S )Nc               
      s|   z&t jj   jjd} W n, tk
rR } ztd|W 5 d }~X Y nX | j	
ddkrntd| tj| jS )N)r   r   r   z,Error in communication with timestamp serverzContent-Typezapplication/timestamp-replyz'Timestamp server response is malformed.)requestspostr   dumpr   r   r   IOErrorr   r   getr   TimeStampResploadcontent)Zraw_reser   r   r   r   task3   s.    

 z8HTTPTimeStamper.async_request_tsa_response.<locals>.taskr   )r   r   r&   responser   r%   r   async_request_tsa_response0   s    z*HTTPTimeStamper.async_request_tsa_response)Fr
   NN)__name__
__module____qualname____doc__r   dictr   r   ZTimeStampReqr!   r(   __classcell__r   r   r   r   r	      s   
)r   Z
asn1cryptor   Z%pyhanko_certvalidator._asyncio_compatr   apir   Zcommon_utilsr   r   __all__r	   r   r   r   r   <module>   s   