U
    <g                     @   sJ  d dl Z d dlmZ d dl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 d d	lmZ d
dgZeejddde jde dde jdddedde jddedddde jdd Zeejddde jde dde jdddde jdddedde jd d!dedddd"e jd#d
 ZdS )$    N)ValidationContext)build_vc_kwargstrust_options)signing)pyhanko_exception_manager)IncrementalPdfFileWriter)PdfFileReader)signers
validation)HTTPTimeStamperltv_fix
lta_updateZ	ltaupdatezupdate LTA timestamp)namehelpinfilezr+b)typez--timestamp-urlzURL for timestamp serverT)r   requiredr   defaultz--retroactive-revinfozOTreat revocation info as retroactively valid (i.e. ignore thisUpdate timestamp)F)r   r   is_flagr   show_defaultc              	   C   sT   t  D t| jj|||||}t|}	t|}
t|	|
t	f | W 5 Q R X d S N)
r   r   objconfigr   r   r	   PdfTimeStamperZupdate_archival_timestamp_chainr   )ctxr   validation_contexttrusttrust_replaceother_certstimestamp_urlretroactive_revinfo	vc_kwargstimestamperr r$   G/tmp/pip-unpacked-wheel-w101_d3s/pyhanko/cli/commands/validation/ltv.pyr      s    
 Zltvfixz5add revocation information for a signature to the DSSz--fieldzname of the signature field)r   r   z--apply-lta-timestampz8Apply a document timestamp after adding revocation info.)r   r   r   r   r   r   c	              	      s   |r|st dt| jj||||ddd}	d|	d< t|}
zt fdd|
jD }W n& tk
r~   t d	  d
Y nX t	j
|tf |	dd}|rt|}t|jt|tjtf |	dd d S )Nz8Please specify a timestamp server using --timestamp-url.FT)r    Zallow_fetchingz	hard-failZrevocation_modec                 3   s   | ]}|j  kr|V  qd S r   )
field_name).0sfieldr$   r%   	<genexpr>u   s    
 zltv_fix.<locals>.<genexpr>z(Could not find a PDF signature labelled .)Zin_place)clickZClickExceptionr   r   r   r   nextZembedded_regular_signaturesStopIterationr
   Zadd_validation_infor   r   r	   r   Ztimestamp_pdfr   Z
DEFAULT_MD)r   r   r*   r   Zapply_lta_timestampr   r   r   r   r!   r#   Zemb_sigoutputr"   r$   r)   r%   r   A   sH    "	

  
)r-   Zpyhanko_certvalidatorr   Zpyhanko.cli._trustr   r   Zpyhanko.cli.commands.signingr   Zpyhanko.cli.runtimer   Z$pyhanko.pdf_utils.incremental_writerr   Zpyhanko.pdf_utils.readerr   Zpyhanko.signr	   r
   Zpyhanko.sign.timestampsr   __all__commandargumentZFileoptionstrboolZpass_contextr   r   r$   r$   r$   r%   <module>   sl   	 	