
    Wwgs                      T   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j4                  dej6                  dee   f
dZy)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_cmspdf_outsignature_metasignertimestampernew_field_specc	                 j    ||rt        d      t        ||||      }	|	j                  | ||||      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.
    SSpecifying 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
             U/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/signers/functions.pyr   r      sa    ^ !&:)
 	

 %	J 1%       c	                    K   ||rt        d      t        ||||      }	|	j                  | ||||       d{   S 7 w)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   [   so     ^ !&:)
 	

 %	J **1% +    s   8A?A
pdf_writerfile_spec_stringpayloadcms_obj	file_namec           
      z   t        j                  t        j                               }t        j
                  j                  | |j                         ddt	        j                  ||            }	|j                  dd      d   |z   }
d	x}}|0|j                  dd      d   |z   }t	        j                  ||	
      g}t	        j                  d|||t	        j                  |
|	
      g|d|xs i }t	        j                  | |       t	        j                  d|
||	d|xs i }t	        j                  | |       y	)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(   r2   f_related_filesuf_related_files)r%   r(   r2    )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_kwargsr6   
cms_ef_obj
cms_data_fcms_data_ufr4   speccms_specs                  r!   r   r      sY   ^ ,,'//1
2C))88\\^*''
 9 J "((a03i?J &*)K"&&sA.q1I=!!+ZH
 >> 	)!!*JG
 *	 !r	D 
Z& ~~ #   %2	H 
Z*r"   )NNFNFN)z.sigNNN)__doc__r   typingr   r7   
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   strr9   ContentInfor   r5   r"   r!   <module>rU      s7       # 6 , - /  7
B *.-1AA(A A +&	A
 \*AP *.-1AA(A A +&	A
 \*AR #Y+!Y+Y+ %%Y+ __	Y+ }Y+r"   