
     hs                      `   d Z ddlmZ ddlmZ ddl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 dd
lmZ ddlmZ ddlmZmZ g dZ	 	 	 	 	 	 dde
dededee         dee         f
dZ	 	 	 	 	 	 dde
dededee         dee         f
dZ	 	 	 	 dde
dedej        dej        dee         f
dZdS ) z<
This module defines pyHanko's high-level API entry points.
    )datetime)OptionalN)cms)embed)BasePdfFileWriter)SigFieldSpec)SigningError)TimeStamper   )Signer)PdfSignatureMetadata	PdfSigner)sign_pdfasync_sign_pdfembed_payload_with_cmsFpdf_outsignature_metasignertimestampernew_field_specc	                     ||rt          d          t          ||||          }	|	                    | ||||          S )a  
    Thin convenience wrapper around :meth:`.PdfSigner.sign_pdf`.

    :param pdf_out:
        An :class:`.IncrementalPdfFileWriter`.
    :param bytes_reserved:
        Bytes to reserve for the CMS object in the PDF file.
        If not specified, make an estimate based on a dummy signature.
    :param signature_meta:
        The specification of the signature to add.
    :param signer:
        :class:`.Signer` object to use to produce the signature object.
    :param timestamper:
        :class:`.TimeStamper` object to use to produce any time stamp tokens
        that might be required.
    :param in_place:
        Sign the input in-place. If ``False``, write output to a
        :class:`.BytesIO` object.
    :param existing_fields_only:
        If ``True``, never create a new empty signature field to contain
        the signature.
        If ``False``, a new field may be created if no field matching
        :attr:`~.PdfSignatureMetadata.field_name` exists.
    :param new_field_spec:
        If a new field is to be created, this parameter allows the caller
        to specify the field's properties in the form of a
        :class:`.SigFieldSpec`. This parameter is only meaningful if
        ``existing_fields_only`` is ``False``.
    :param output:
        Write the output to the specified output stream.
        If ``None``, write to a new :class:`.BytesIO` object.
        Default is ``None``.
    :return:
        The output stream containing the signed output.
    NSSpecifying a signature field spec is not meaningful when existing_fields_only=True.r   r   existing_fields_onlybytes_reservedin_placeoutput)r	   r   r   
r   r   r   r   r   r   r   r   r   
pdf_signers
             Z/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/sign/signers/functions.pyr   r      sx    ^ !&:!)
 
 	

 %	  J 1%        c	                    K   ||rt          d          t          ||||          }	|	                    | ||||           d{V S )a  
    Thin convenience wrapper around :meth:`.PdfSigner.async_sign_pdf`.

    :param pdf_out:
        An :class:`.IncrementalPdfFileWriter`.
    :param bytes_reserved:
        Bytes to reserve for the CMS object in the PDF file.
        If not specified, make an estimate based on a dummy signature.
    :param signature_meta:
        The specification of the signature to add.
    :param signer:
        :class:`.Signer` object to use to produce the signature object.
    :param timestamper:
        :class:`.TimeStamper` object to use to produce any time stamp tokens
        that might be required.
    :param in_place:
        Sign the input in-place. If ``False``, write output to a
        :class:`.BytesIO` object.
    :param existing_fields_only:
        If ``True``, never create a new empty signature field to contain
        the signature.
        If ``False``, a new field may be created if no field matching
        :attr:`~.PdfSignatureMetadata.field_name` exists.
    :param new_field_spec:
        If a new field is to be created, this parameter allows the caller
        to specify the field's properties in the form of a
        :class:`.SigFieldSpec`. This parameter is only meaningful if
        ``existing_fields_only`` is ``False``.
    :param output:
        Write the output to the specified output stream.
        If ``None``, write to a new :class:`.BytesIO` object.
        Default is ``None``.
    :return:
        The output stream containing the signed output.
    Nr   r   r   )r	   r   r   r   s
             r!   r   r   [   s      ^ !&:!)
 
 	

 %	  J **1% +         r"   .sig
pdf_writerfile_spec_stringpayloadcms_obj	file_namec           
      z   t          j        t          j                              }t          j                            | |                                ddt	          j        ||                    }	|	                    dd          d         |z   }
d	x}}|6|	                    dd          d         |z   }t	          j
        ||	
          g}t	          j        d|||t	          j
        |
|	
          g|d|pi }t	          j        | |           t	          j        d|
||	d|pi }t	          j        | |           d	S )a  
    Embed some data as an embedded file stream into a PDF, and associate it
    with a CMS object.

    The resulting CMS object will also be turned into an embedded file, and
    associated with the original payload through a related file relationship.

    This can be used to bundle (non-PDF) detached signatures with PDF
    attachments, for example.

    .. versionadded:: 0.7.0

    :param pdf_writer:
        The PDF writer to use.
    :param file_spec_string:
        See :attr:`~pyhanko.pdf_utils.embed.FileSpec.file_spec_string` in
        :class:`~pyhanko.pdf_utils.embed.FileSpec`.
    :param payload:
        Payload object.
    :param cms_obj:
        CMS object pertaining to the payload.
    :param extension:
        File extension to use for the CMS attachment.
    :param file_name:
        See :attr:`~pyhanko.pdf_utils.embed.FileSpec.file_name` in
        :class:`~pyhanko.pdf_utils.embed.FileSpec`.
    :param file_spec_kwargs:
        Extra arguments to pass to the
        :class:`~pyhanko.pdf_utils.embed.FileSpec` constructor
        for the main attachment specification.
    :param cms_file_spec_kwargs:
        Extra arguments to pass to the
        :class:`~pyhanko.pdf_utils.embed.FileSpec` constructor
        for the CMS attachment specification.
    )tzFzapplication/pkcs7-mime)creation_datemodification_date)r%   datacompress	mime_typeparams.r   r   N)embedded_data)r&   r)   r3   f_related_filesuf_related_files)r&   r)   r3    )r   nowtzlocalget_localzoner   EmbeddedFileObjectfrom_file_datadumpEmbeddedFileParamsrsplitRelatedFileSpecFileSpec
embed_file)r%   r&   r'   r(   	extensionr)   file_spec_kwargscms_file_spec_kwargsr7   
cms_ef_obj
cms_data_fcms_data_ufr5   speccms_specs                  r!   r   r      s   ^ ,'/11
2
2
2C)88\\^^*'
 
 
 9  J "((a003i?J &*)K"&&sA..q1I=!+ZHHH
 > 	)!*JGGG
 *	 	 !r	 	D 
Z&&& ~ #    %2	 H 
Z*****r"   )NNFNFN)r$   NNN)__doc__r   typingr   r8   
asn1cryptor   pyhanko.pdf_utilsr   pyhanko.pdf_utils.writerr   pyhanko.sign.fieldsr   pyhanko.sign.generalr	   pyhanko.sign.timestampsr
   pdf_cmsr   r    r   r   __all__r   r   strr:   ContentInfor   r6   r"   r!   <module>rV      s3                       # # # # # # 6 6 6 6 6 6 , , , , , , - - - - - - / / / / / /       7 7 7 7 7 7 7 7
B
B
B *.-1A AA(A A +&	A
 \*A A A AP *.-1A AA(A A +&	A
 \*A A A AR #Y+ Y+!Y+Y+ %Y+ _	Y+ }Y+ Y+ Y+ Y+ Y+ Y+r"   