U
    :vhp                     @   sz   d Z ddl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lmZ G d	d
 d
Zdd Zdd ZdZedZdS )z
Module dedicated to document signature generation.

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    N)timezone)patch   )build_obj_dictName)create_dictionary_string)buffer_substc                   @   s    e Zd ZdddZdddZdS )	SignatureNc                 C   sN   t d| _t d| _t d| _|| _|| _|| _|| _t| _	dt
 d | _d S )NZSigzAdobe.PPKLitezadbe.pkcs7.detached<>)r   typefilterZ
sub_filtercontact_infolocationmreason _SIGNATURE_BYTERANGE_PLACEHOLDERZ
byte_range_SIGNATURE_CONTENTS_PLACEHOLDERcontents)selfr   r   r   r    r   -/tmp/pip-unpacked-wheel-dvf6lv8i/fpdf/sign.py__init__   s    


zSignature.__init__c                    s(   t  fddt D ||d}t|S )Nc                    s   i | ]}|t  |qS r   )getattr).0keyr   r   r   
<dictcomp>$   s      z'Signature.serialize.<locals>.<dictcomp>)_security_handler_obj_id)r   dirpdf_dict)r   r   r   Zobj_dictr   r   r   	serialize"   s    zSignature.serialize)NNNN)NN)__name__
__module____qualname__r   r"   r   r   r   r   r	      s   
r	   c              	      s   t d}||}|t| }	d|d |	d t||	 d f}
t|td|
 }t|}||d|
d   |||
d d  G  fddd}t	d	|| j
}|d||||d
| d}t|d}t|t|kst|||dS )z
    Perform PDF signing based on the content of the buffer, performing substitutions on it.
    The signing operation does not alter the buffer size
    latin1r   r   z[%010d %010d %010d %010d]N   c                       s   e Zd Ze fddZdS )z#sign_content.<locals>.mock_datetimec                    s     tjS )N)
astimezoner   utc)tz	sign_timer   r   nowF   s    z'sign_content.<locals>.mock_datetime.nowN)r#   r$   r%   staticmethodr-   r   r+   r   r   mock_datetimeE   s   r/   zendesive.signer.datetimeT)Zdataur   certZ
othercertshashalgoattrsZsigned_value)r   encodefindlenr   r   hashlibnewupdater   signdigest_pkcs11_alignedAssertionErrorreplace)Zsignerbufferr   r0   Zextra_certsr1   r,   Zsig_placeholderstart_indexZ	end_indexZcontent_rangeZcontent_hashr/   r9   r   r   r+   r   sign_content+   s4    

 
	r@   c                 C   s(   d dd | D } | ddt|    S )N c                 s   s   | ]}|d V  qdS )Z02xNr   )r   ir   r   r   	<genexpr>\   s     z"_pkcs11_aligned.<locals>.<genexpr>0i @  )joinr5   )datar   r   r   r;   [   s    r;   z-[0000000000 0000000000 0000000000 0000000000])r   )__doc__r6   datetimer   Zunittest.mockr   Zsyntaxr   r   r   r!   utilr   r	   r@   r;   r   r   r   r   r   r   <module>   s   0