§
    ¥”jiD  ã                   ó*  — 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mZmZmZ dd	lmZ dd
lmZ ddlmZmZ g d¢Z ed¬¦  «         G d„ d¦  «        ¦   «         Z G d„ dej        ¦  «        Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Zdej        defd„Zdddddddddœdedee         deee	j                          d eej                  d!ed"ee         d#ee         d$ej!        fd%„Z"dS )&zO
Utility classes for handling embedded files in PDFs.

.. versionadded:: 0.7.0
é    N)Ú	dataclass)Údatetime)ÚListÚOptional)Úx509é   )ÚcryptÚgenericÚmiscÚwriter)ÚRecipientEncryptionPolicy)Úget_courier)Úpdf_nameÚ
pdf_string)ÚEmbeddedFileObjectÚEmbeddedFileParamsÚFileSpecÚRelatedFileSpecÚ
embed_fileÚwrap_encrypted_payloadT)Úfrozenc                   óf   — e Zd ZU dZeed<   	 dZeed<   	 dZee	         ed<   	 dZ
ee	         ed<   dS )r   TÚ
embed_sizeÚembed_checksumNÚcreation_dateÚmodification_date)Ú__name__Ú
__module__Ú__qualname__r   ÚboolÚ__annotations__r   r   r   r   r   © ó    úf/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/pyhanko/pdf_utils/embed.pyr   r      sv   € € € € € € à€J�ÐÐÑðð  €N�DÐÐÑðð )-€M�8˜HÔ%Ð,Ð,Ñ,ðð -1Ð�x Ô)Ð0Ð0Ñ0ðð r#   r   c                   ó¼   ‡ — e Zd Ze	 	 	 ddej        dedee         dee	         dd f
d„¦   «         Z
	 	 	 	 	 ddej        dee         dee	         fˆ fd	„Zdˆ fd
„	Zˆ xZS )r   TNÚ
pdf_writerÚdataÚparamsÚ	mime_typeÚreturnc                 óX   — t          ||||¬¦  «        }|r|                     ¦   «          |S )aë  
        Construct an embedded file object from file data.

        This is a very thin wrapper around the constructor, with a slightly
        less intimidating API.

        .. note::
            This method will not register the embedded file into the document's
            embedded file namespace, see :func:`.embed_file`.

        :param pdf_writer:
            PDF writer to use.
        :param data:
            File contents, as a :class:`bytes` object.
        :param compress:
            Whether to compress the embedded file's contents.
        :param params:
            Optional embedded file parameters.
        :param mime_type:
            Optional MIME type string.
        :return:
            An embedded file object.
        )r&   Ústream_datar(   r)   )r   Úcompress)Úclsr&   r'   r-   r(   r)   Úresults          r$   Úfrom_file_dataz!EmbeddedFileObject.from_file_data?   sD   € õB $Ø!ØØØð	
ñ 
ô 
ˆð ð 	Ø�OŠOÑÔÐàˆr#   c                 ó  •— t          ¦   «                              ||||j        ¬¦  «         t          j        d¦  «        | d<   |�t          j        d|z   ¦  «        | d<   |                     | ¦  «        | _        || _        d S )N)Ú	dict_datar,   Úencoded_dataÚhandlerz/EmbeddedFileú/Typeú/z/Subtype)ÚsuperÚ__init__Úsecurity_handlerr
   r   Ú
add_objectÚef_stream_refr(   )Úselfr&   r2   r,   r3   r(   r)   Ú	__class__s          €r$   r8   zEmbeddedFileObject.__init__k   s‹   ø€ õ 	‰Œ×ÒØØ#Ø%ØÔ/ð	 	ñ 	
ô 	
ð 	
õ  Ô(¨Ñ9Ô9ˆˆW‰ØÐ Ý&Ô/°°i±Ñ@Ô@ˆD�ÑØ'×2Ò2°4Ñ8Ô8ˆÔØˆŒˆˆr#   c                 ó†  •— |�9| j         s2|j        }|j        }|j        }|�||k    r|                      |¦  «         | j        }|�×t          j        ¦   «         x| d<   }|j        r)t          j	        t          | j        ¦  «        ¦  «        |d<   |j        rBt          j        | j        ¦  «                             ¦   «         }	t          j        |	¦  «        |d<   |j        �t          j        |j        ¦  «        |d<   |j        �t          j        |j        ¦  «        |d<   t)          ¦   «                              |||¬¦  «         d S )Nz/Paramsz/Sizez	/CheckSumz/CreationDatez/ModDate)r4   Úcontainer_ref)Ú_has_crypt_filterÚcrypt_filter_configÚembedded_file_filter_nameÚstream_filter_nameÚadd_crypt_filterr(   r
   ÚDictionaryObjectr   ÚNumberObjectÚlenr'   r   ÚhashlibÚmd5ÚdigestÚByteStringObjectr   Úpdf_dater   r7   Úwrite_to_stream)r<   Ústreamr4   r?   ÚcfcÚef_filter_namerC   r(   Ú
param_dictÚchecksumr=   s             €r$   rM   z"EmbeddedFileObject.write_to_stream€   sa  ø€ ð Ð tÔ'=ÐØÔ-ˆCØ Ô:ˆNØ!$Ô!7ÐàÐ*Ø"Ð&8Ò8Ð8à×%Ò% nÑ5Ô5Ð5ð ”ˆØÐÝ+2Ô+CÑ+EÔ+EÐEˆD�‰O˜jØÔ ð KÝ&-Ô&:½3¸t¼y¹>¼>Ñ&JÔ&J�
˜7Ñ#ØÔ$ð MÝ"œ; t¤yÑ1Ô1×8Ò8Ñ:Ô:�Ý*1Ô*BÀ8Ñ*LÔ*L�
˜;Ñ'ØÔ#Ð/Ý.5Ô.>ØÔ(ñ/ô /�
˜?Ñ+ð Ô'Ð3Ý)0Ô)9ØÔ,ñ*ô *�
˜:Ñ&õ 	‰Œ×ÒØ˜G°=ð 	 ñ 	
ô 	
ð 	
ð 	
ð 	
r#   )TNN)NNNNN)NN)r   r   r   Úclassmethodr   ÚBasePdfFileWriterÚbytesr   r   Ústrr0   r8   rM   Ú__classcell__)r=   s   @r$   r   r   >   s  ø€ € € € € Øð
 Ø/3Ø#'ð)ð )àÔ,ð)ð ð)ð
 Ð+Ô,ð)ð ˜C”=ð)ð 
ð)ð )ð )ñ „[ð)ð\ ØØØ/3Ø#'ðð àÔ,ðð Ð+Ô,ðð ˜C”=ðð ð ð ð ð ð*"
ð "
ð "
ð "
ð "
ð "
ð "
ð "
ð "
ð "
r#   r   c                   óT   — e Zd ZU dZeed<   	 eed<   	 eded          fd„¦   «         Z	dS )r   z=
    Dataclass modelling a RelatedFile construct in PDF.
    ÚnameÚembedded_dataÚlstc                 óF   ‡— ˆfd„}t          j         |¦   «         ¦  «        S )Nc               3   óh   •K  — ‰D ]+} t          j        | j        ¦  «        V — | j        j        V — Œ,d S )N)r
   r   rY   rZ   r;   )Úrfsr[   s    €r$   Ú_genz/RelatedFileSpec.fmt_related_files.<locals>._gen¼   sN   øè è € Øð 6ð 6�ÝÔ(¨¬Ñ2Ô2Ð2Ð2Ð2ØÔ'Ô5Ð5Ð5Ð5Ð5ð6ð 6r#   )r
   ÚArrayObject)r.   r[   r_   s    ` r$   Úfmt_related_filesz!RelatedFileSpec.fmt_related_filesº   s5   ø€ ð	6ð 	6ð 	6ð 	6ð 	6õ
 Ô" 4 4¡6¤6Ñ*Ô*Ð*r#   N)
r   r   r   Ú__doc__rV   r!   r   rS   r   ra   r"   r#   r$   r   r   ¥   sp   € € € € € € ðð ð €I€I�Iðð &Ð%Ð%Ñ%ðð
 ð+ DÐ):Ô$;ð +ð +ð +ñ „[ð+ð +ð +r#   r   c                   ó   — e Zd ZU dZeed<   	 dZee         ed<   	 dZee	         ed<   	 dZ
ee         ed<   	 dZeej                 ed<   	 dZeee                  ed<   	 dZeee                  ed	<   	 d
ej        fd„ZdS )r   zD
    Dataclass modelling an embedded file description in a PDF.
    Úfile_spec_stringNÚ	file_namerZ   ÚdescriptionÚaf_relationshipÚf_related_filesÚuf_related_filesr*   c                 óÈ  — t          j        t          d¦  «        t          d¦  «        t          d¦  «        t          | j        ¦  «        i¦  «        }| j        �t          | j        ¦  «        |d<   | j        �Ht          j        t          d¦  «        | j        j        i¦  «        x|d<   }| j        �| j        j        |d<   | j        �t          j	        | j        ¦  «        |d<   | j
        �
| j
        |d<   | j        }| j        }|s|r]t          j        ¦   «         x|d	<   }|rt                               |¦  «        |d<   |r$| j        �t                               |¦  «        |d<   |S )
z>
        Represent the file spec as a PDF dictionary.
        r5   z	/Filespecz/FNz/UFz/EFz/Descz/AFRelationshipz/RF)r
   rE   r   r   rd   re   rZ   r;   rf   ÚTextStringObjectrg   rh   ri   r   ra   )r<   r/   Úef_dictÚ	f_relatedÚ
uf_relatedÚrfs         r$   Úas_pdf_objectzFileSpec.as_pdf_objectù   ss  € õ
 Ô)å˜Ñ!Ô!¥8¨KÑ#8Ô#8Ý˜‘”¥
¨4Ô+@Ñ AÔ Aðñ
ô 
ˆð Œ>Ð%Ý& t¤~Ñ6Ô6ˆF�5‰MàÔÐ)Ý&-Ô&>å˜T‘N”N DÔ$6Ô$Dðñ'ô 'ð ˆF�5‰M˜Gð
 Œ~Ð)Ø!%Ô!3Ô!A�˜‘àÔÐ'Ý%Ô6°tÔ7GÑHÔHˆF�7‰OàÔÐ+Ø(,Ô(<ˆFÐ$Ñ%àÔ(ˆ	ØÔ*ˆ
Øð 	J˜
ð 	JÝ!(Ô!9Ñ!;Ô!;Ð;ˆF�5‰M˜BØð HÝ*×<Ò<¸YÑGÔG��4‘Øð J˜dœnÐ8Ý+×=Ò=¸jÑIÔI��5‘	àˆr#   )r   r   r   rb   rV   r!   re   r   rZ   r   rf   rg   r
   Ú
NameObjectrh   r   r   ri   rE   rp   r"   r#   r$   r   r   Ä   s  € € € € € € ðð ð ÐÐÑðð  $€Iˆx˜Œ}Ð#Ð#Ñ#ðð 37€M�8Ð.Ô/Ð6Ð6Ñ6ðð
 "&€K�˜#”Ð%Ð%Ñ%ðð 59€O�X˜gÔ0Ô1Ð8Ð8Ñ8ðð 8<€O�X˜d ?Ô3Ô4Ð;Ð;Ñ;ðð 9=Ð�h˜t OÔ4Ô5Ð<Ð<Ñ<ðð&˜wÔ7ð &ð &ð &ð &ð &ð &r#   r   r&   Úspecc                 óÒ  — |j         }|€t          j        d¦  «        ‚|                     ¦   «         }| j        }	 |d         }nO# t
          $ rB t          j        ¦   «         }|                      |¦  «        |d<   |  	                    ¦   «          Y nw xY w	 |d         }nP# t
          $ rC t          j        ¦   «         }|                      |¦  «        |d<   |  
                    |¦  «         Y nw xY wd|v rt          d¦  «        ‚	 |d         }nP# t
          $ rC t          j        ¦   «         }|                      |¦  «        |d<   |  
                    |¦  «         Y nw xY w|                     t          j        |j        ¦  «        ¦  «         |                      |¦  «        }|                     |¦  «         |  
                    |¦  «         |j        �†|                      d¬¦  «         	 |d	         }	nO# t
          $ rB t          j        ¦   «         }	|                      |	¦  «        |d	<   |  	                    ¦   «          Y nw xY w|	                     |¦  «         dS |                      d
¬¦  «         dS )zè
    Embed a file in the document-wide embedded file registry of a PDF writer.

    :param pdf_writer:
        PDF writer to house the embedded file.
    :param spec:
        File spec describing the embedded file.
    :return:
    Nz/File spec does not have an embedded file streamz/Namesz/EmbeddedFilesz/Kidsz,Only flat name trees are supported right now)é   r   )Úversionz/AF)r   é   )rZ   r   ÚPdfWriteErrorrp   ÚrootÚKeyErrorr
   rE   r:   Úupdate_rootÚupdate_containerÚNotImplementedErrorr`   Úappendr   rd   rg   Úensure_output_version)
r&   rr   Ú	ef_streamÚspec_objrx   Ú
names_dictÚef_name_treeÚef_name_arrÚspec_obj_refÚroot_af_arrs
             r$   r   r   "  sÈ  € ð Ô"€IàÐÝÔ Ø=ñ
ô 
ð 	
ð ×!Ò!Ñ#Ô#€HàŒ?€Dð!Ø˜(”^ˆ
ˆ
øÝð !ð !ð !ÝÔ-Ñ/Ô/ˆ
Ø#×.Ò.¨zÑ:Ô:ˆˆX‰Ø×ÒÑ Ô Ð Ð Ð ð!øøøð
0Ø!Ð"2Ô3ˆˆøÝð 0ð 0ð 0ÝÔ/Ñ1Ô1ˆØ'1×'<Ò'<¸\Ñ'JÔ'Jˆ
Ð#Ñ$Ø×#Ò# JÑ/Ô/Ð/Ð/Ð/ð0øøøð �,ÐÐÝ!Ø:ñ
ô 
ð 	
ð2Ø" 8Ô,ˆˆøÝð 2ð 2ð 2ÝÔ)Ñ+Ô+ˆØ!+×!6Ò!6°{Ñ!CÔ!Cˆ�XÑØ×#Ò# LÑ1Ô1Ð1Ð1Ð1ð2øøøð
 ×Ò•wÔ)¨$Ô*?Ñ@Ô@ÑAÔAÐAØ×(Ò(¨Ñ2Ô2€LØ×Ò�|Ñ$Ô$Ð$Ø×Ò Ñ,Ô,Ð,àÔÐ'Ø×(Ò(°Ð(Ñ8Ô8Ð8ð	%Ø˜uœ+ˆKˆKøÝð 	%ð 	%ð 	%Ý!Ô-Ñ/Ô/ˆKØ$×/Ò/°Ñ<Ô<ˆD�‰KØ×"Ò"Ñ$Ô$Ð$Ð$Ð$ð	%øøøð 	×Ò˜<Ñ(Ô(Ð(Ð(Ð(à×(Ò(°Ð(Ñ8Ô8Ð8Ð8Ð8sK   ºA ÁA	BÂBÂB ÂA
C)Ã(C)Ä D	 Ä	A
EÅEÇ"G+ Ç+A	H7È6H7zattachment.pdfzWrapped document)ÚpasswordÚcertsr9   rd   r(   re   rf   Úinclude_explanation_pageÚplaintext_payloadr†   r‡   r9   rd   r(   re   r*   c          
      óª  — t          j        ¦   «         }	|�€D|du |du k    rt          d¦  «        ‚|€´|€J ‚t          j        ddd¬¦  «        }
|
                     ¦   «          t          j        t          j        j        t          j	        j
        ddt          j        t          j        |
it          j        ¬¦  «        ¬¦  «        }|
                     |t          ¦   «         ¬¦  «         nut          j        d¬	¦  «        }|                     ¦   «          t          j                             |t          j        t          j        |it          j        ¬¦  «        d¬
¦  «        }|	                     |¦  «         t)          j        ¦   «         x|	j        d<   }t/          d¦  «        |d<   t)          j        |¦  «        |d<   t/          d¦  «        |d<   t2                               |	| d|pt7          ¦   «         ¬¦  «        }t9          ||||¬¦  «        }t;          |	|¦  «         |rºt)          j        t/          d¦  «        t)          j        t/          d¦  «        t=          |	¦  «        i¦  «        i¦  «        }d}t)          j        |                      d¦  «        ¬¦  «        }t          j!        |	 "                    |¦  «        d|¬¦  «        }|	 #                    |¦  «         |	S )a|
  
    Include a PDF document as an encrypted attachment in a wrapper document.

    This function sets certain flags in the wrapper document's collection
    dictionary to instruct compliant PDF viewers to display the attachment
    instead of the wrapping document. Viewers that do not fully support
    PDF collections will display a landing page instead, explaining
    how to open the attachment manually.

    Using this method mitigates some weaknesses in the PDF standard's encryption
    provisions, and makes it harder to manipulate the encrypted attachment
    without knowing the encryption key.

    .. danger::
        Until PDF supports authenticated encryption mechanisms, this is
        a mitigation strategy, not a foolproof defence mechanism.

    .. warning::
        While users of viewers that do not support PDF collections can still
        open the attached file manually, the viewer still has to support
        PDF files where only the attachments are encrypted.

    .. note::
        This is not quite the same as the "unencrypted wrapper document"
        pattern discussed in the PDF 2.0 specification. The latter is intended
        to support nonstandard security handlers. This function uses a standard
        security handler on the wrapping document to encrypt the attachment
        as a binary blob.
        Moreover, the functionality in this function is available in PDF 1.7
        viewers as well.

    :param plaintext_payload:
        The plaintext payload (a binary representation of a PDF document).
    :param security_handler:
        The security handler to use on the wrapper document.
        If ``None``, a security handler will be constructed based on the
        ``password`` or ``certs`` parameter.
    :param password:
        Password to encrypt the attachment with.
        Will be ignored if ``security_handler`` is provided.
    :param certs:
        Encrypt the file using PDF public-key encryption, targeting the
        keys in the provided certificates.
        Will be ignored if ``security_handler`` is provided.
    :param file_spec_string:
        PDFDocEncoded file spec string for the attachment.
    :param params:
        Embedded file parameters to use.
    :param file_name:
        Unicode file name for the attachment.
    :param description:
        Description for the attachment
    :param include_explanation_page:
        If ``False``, do not generate an explanation page in the wrapper
        document. This setting could be useful if you want to customise the
        wrapper document's behaviour yourself.
    :return:
        A :class:`~writer.PdfFileWriter` representing the wrapper document.
    NzSIf 'security_handler' is not provided, exactly one of 'password' or 'cert' must be.é    F)ÚkeylenÚacts_as_defaultÚencrypt_metadata)Údefault_file_filter)ru   Úpubkey_handler_subfilterÚlegacy_keylenrŽ   rA   )Úpolicy)rŒ   )rA   rŽ   z/Collectionr5   z/Dz/Hz/Viewzapplication/pdf)r'   r)   r(   )rd   re   rZ   rf   z/Fontz/F1a¶  
        BT
            /F1 10 Tf 10 830 Td 12 TL
            (This document is a wrapper for an encrypted attachment.) '
            (Your viewer should prompt for a password and ) '
            (open the attached file automatically.) Tj
            (If not, navigate to the attached document manually.) ' T*
            (In addition, your viewer must support encryption ) '
            (scoped to embedded files.) Tj
        ET
        Úlatin1)r,   )r   r   g
×£p=š‚@g…ëQ¸OŠ@)ÚcontentsÚ	media_boxÚ	resources)$r   ÚPdfFileWriterÚ
ValueErrorr	   ÚPubKeyAESCryptFilterÚset_embedded_onlyÚPubKeySecurityHandlerÚSecurityHandlerVersionÚAES256ÚPubKeyAdbeSubFilterÚS5ÚCryptFilterConfigurationÚDEF_EMBEDDED_FILEÚadd_recipientsr   ÚStandardAESCryptFilterÚStandardSecurityHandlerÚbuild_from_pwÚSTD_CFÚ_assign_security_handlerr
   rE   rx   r   rk   r   r0   r   r   r   r   ÚStreamObjectÚencodeÚ
PageObjectr:   Úinsert_page)r‰   r†   r‡   r9   rd   r(   re   rf   rˆ   ÚwÚ	pubkey_cfÚstd_cfÚcollection_dictÚef_objrr   r–   Ústream_contentrN   Úexplanation_pages                      r$   r   r   g  s  € õN 	ÔÑÔ€AàÑØ˜Ð %¨4 -Ò0Ð0Ýð?ñô ð ð ÐØÐ$Ð$Ð$åÔ2Ø¨5À5ðñ ô ˆIð ×'Ò'Ñ)Ô)Ð)Ý$Ô:ÝÔ4Ô;Ý).Ô)BÔ)EØ"Ø!&Ý$)Ô$BÝÔ,¨iÐ8Ý(-Ô(?ð%ñ %ô %ð	 ñ 	 ô 	 Ðð ×$Ò$ UÕ3LÑ3NÔ3NÐ$ÑOÔOÐOÐOõ Ô1¸Ð<Ñ<Ô<ˆFØ×$Ò$Ñ&Ô&Ð&Ý$Ô<×JÒJØÝ$)Ô$BÝ”\ 6Ð*ÅÄð%ñ %ô %ð "'ð  Kñ  ô  Ðð ×ÒÐ/Ñ0Ô0Ð0å.5Ô.FÑ.HÔ.HÐH€A„Fˆ=Ñ˜OÝ'¨Ñ6Ô6€O�GÑÝ#Ô4Ð5EÑFÔF€O�DÑÝ'¨™~œ~€O�GÑå×.Ò.Ø	ØØ#ØÐ-Õ+Ñ-Ô-ð	 /ñ ô €Fõ Ø)ØØØð	ñ ô €Dõ ˆq�$ÑÔÐàð "(ÝÔ,å˜Ñ!Ô!¥7Ô#;Ý˜e‘_”_¥k°!¡n¤nÐ5ñ$ô $ðñ
ô 
ˆ	ð
ˆõ Ô%Ø&×-Ò-¨hÑ7Ô7ð
ñ 
ô 
ˆõ "Ô,Ø—\’\ &Ñ)Ô)à,Øð	
ñ 
ô 
Ðð 	
�ŠÐ&Ñ'Ô'Ð'à€Hr#   )#rb   rH   Údataclassesr   r   Útypingr   r   Ú
asn1cryptor   Ú r	   r
   r   r   Úcrypt.pubkeyr   Ú
font.basicr   r   r   Ú__all__r   r¨   r   r   r   rT   r   rU   rV   ÚCertificateÚSecurityHandlerr—   r   r"   r#   r$   ú<module>r¼      sÑ  ððð ð €€€Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !à Ð Ð Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø #Ð #Ð #Ð #Ð #Ð #Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )ðð ð €ð €�$ÐÑÔðð ð ð ð ñ ô ñ Ôðð@d
ð d
ð d
ð d
ð d
˜Ô-ñ d
ô d
ð d
ðN €�$ÐÑÔð+ð +ð +ð +ð +ñ +ô +ñ Ôð+ð< €�$ÐÑÔðZð Zð Zð Zð Zñ Zô Zñ ÔðZðzB9˜6Ô3ð B9¸8ð B9ð B9ð B9ð B9ðP #Ø.2Ø8<Ø,Ø+/Ø#Ø"Ø!ðfð fð fØðfð �sŒmðfð �D˜Ô)Ô*Ô+ð	fð
 ˜uÔ4Ô5ðfð ðfð Ð'Ô(ðfð ˜Œ}ðfð Ôðfð fð fð fð fð fr#   