
    }fp                         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
          Zd Z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                       e Zd ZddZddZdS )	SignatureNc                     t          d          | _        t          d          | _        t          d          | _        || _        	 || _        	 || _        	 || _        	 t          | _	        dt          z   dz   | _        d S )NSigzAdobe.PPKLitezadbe.pkcs7.detached<>)r   typefilter
sub_filtercontact_infolocationmreason _SIGNATURE_BYTERANGE_PLACEHOLDER
byte_range_SIGNATURE_CONTENTS_PLACEHOLDERcontents)selfr   r   r   r   s        B/var/www/rtfcompare/venv/lib/python3.11/site-packages/fpdf/sign.py__init__zSignature.__init__   st    KK	?++455(p ?$:==C    c                 x     t           fdt                     D             ||          }t          |          S )Nc                 2    i | ]}|t          |          S  )getattr).0keyr   s     r   
<dictcomp>z'Signature.serialize.<locals>.<dictcomp>$   s%    :::S'$$$:::r   )_security_handler_obj_id)r   dirpdf_dict)r   r&   r'   obj_dicts   `   r   	serializezSignature.serialize"   sJ    !::::D		:::/
 
 

 !!!r   )NNNN)NN)__name__
__module____qualname__r   r+   r!   r   r   r   r      s@        D D D D" " " " " "r   r   c           
         t                               d          }|                    |          }|t          |          z   }	d|dz
  |	dz   t          |          |	z
  dz
  f}
t	          |t
          d|
z            }t          j        |          }|                    |d|
d                             |                    ||
d         d                     G fdd          } t          d	|          | j
                  } |d||||d
|                                          }t          |                              d          }t          |          t          |          k    sJ |                    ||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                   *    e Zd Ze fd            ZdS )#sign_content.<locals>.mock_datetimec                 B                         t          j                  S )N)
astimezoner   utc)tz	sign_times    r   nowz'sign_content.<locals>.mock_datetime.nowF   s    ''555r   N)r,   r-   r.   staticmethodr9   )r8   s   r   mock_datetimer3   E   s8        		6 	6 	6 	6 
	6 	6 	6r   r;   zendesive.signer.datetimeT)dataur$   cert
othercertshashalgoattrssigned_value)r   encodefindlenr	   r   hashlibnewupdater   signdigest_pkcs11_alignedreplace)signerbufferr$   r=   extra_certsr?   r8   sig_placeholderstart_index	end_indexcontent_rangecontent_hashr;   rH   r   s         `        r   sign_contentrT   +   s    6<<XFFO++o..Kc/222IaQFi8ORS8STM(#m3 F ;x((L1q!112333}Q/1123336 6 6 6 6 6 6 6 6 6
 <5+];;FKHHDt!((**  H x((//99H3x==0000>>/8Q777r   c                 p    d                     d | D                       } | ddt          |           z
  z  z   S )N c              3      K   | ]}|d V  	dS )02xNr!   )r#   is     r   	<genexpr>z"_pkcs11_aligned.<locals>.<genexpr>\   s&      ,,!a::,,,,,,r   0i @  )joinrD   )datas    r   rJ   rJ   [   s=    77,,t,,,,,D##d))+,,,r   z-[0000000000 0000000000 0000000000 0000000000])r   )__doc__rE   datetimer   unittest.mockr   syntaxr   r   r   r)   utilr	   r   rT   rJ   r   r   r!   r   r   <module>rc      s                  ( ( ( ( ( ( ( ( 8 8 8 8 8 8      " " " " " " " "2-8 -8 -8`- - -
 $S  "1/$"7"7   r   