
    h5j                        d Z ddlmZ ddlmZmZmZmZ ddlm	Z	  G d de      Z
 e
       Z G d d      Z G d	 d
e      Zy)zFor managing PDF encryption.    )annotations)AnyLiteral
NamedTuplecast)EncryptionMethodc                      e Zd ZU dZdZded<   	 dZded<   	 dZded<   	 dZded<   	 dZ	ded	<   	 dZ
ded
<   	 dZded<   	 dZded<   y)Permissionsan  Stores the user-level permissions for an encrypted PDF.

    A compliant PDF reader/writer should enforce these restrictions on people
    who have the user password and not the owner password. In practice, either
    password is sufficient to decrypt all document contents. A person who has
    the owner password should be allowed to modify the document in any way.
    pikepdf does not enforce the restrictions in any way; it is up to application
    developers to enforce them as they see fit.

    Unencrypted PDFs implicitly have all permissions allowed. Permissions can
    only be changed when a PDF is saved.
    Tboolaccessibilityextractmodify_annotationFmodify_assemblymodify_formmodify_otherprint_lowresprint_highresN)__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r        O/var/www/html/qr/venv/lib/python3.12/site-packages/pikepdf/models/encryption.pyr
   r
      sv     M4 GT%"t"'!OT!.K#L$(L$9M4:r   r
   c                      e Zd ZdZddZedd       Zedd       Zedd       Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zd Zy)EncryptionInfoa  Reports encryption information for an encrypted PDF.

    This information may not be changed, except when a PDF is saved.
    This object is not used to specify the encryption settings to save
    a PDF, due to non-overlapping information requirements.
    c                    || _         y)zInitialize EncryptionInfo.

        Generally pikepdf will initialize and return it.

        Args:
            encdict: Python dictionary containing encryption settings.
        N)_encdict)selfencdicts     r   __init__zEncryptionInfo.__init__F   s      r   c                2    t        | j                  d         S )z(Revision number of the security handler.Rintr   r    s    r   r$   zEncryptionInfo.RP        4==%&&r   c                2    t        | j                  d         S )z"Version of PDF password algorithm.Vr%   r'   s    r   r*   zEncryptionInfo.VU   r(   r   c                2    t        | j                  d         S )zPReturn encoded permission bits.

        See :meth:`Pdf.allow` instead.
        Pr%   r'   s    r   r,   zEncryptionInfo.PZ   s     4==%&&r   c                4    t        d| j                  d         S )z)Encryption method used to encode streams.r   streamr   r   r'   s    r   stream_methodzEncryptionInfo.stream_methodb        &h(?@@r   c                4    t        d| j                  d         S )z)Encryption method used to encode strings.r   stringr/   r'   s    r   string_methodzEncryptionInfo.string_methodg   r1   r   c                4    t        d| j                  d         S )z0Encryption method used to encode the whole file.r   filer/   r'   s    r   file_methodzEncryptionInfo.file_methodl   s     &f(=>>r   c                2    t        | j                  d         S )aH  If possible, return the user password.

        The user password can only be retrieved when a PDF is opened
        with the owner password and when older versions of the
        encryption algorithm are used.

        The password is always returned as ``bytes`` even if it has
        a clear Unicode representation.
        user_passwdbytesr   r'   s    r   user_passwordzEncryptionInfo.user_passwordq   s     T]]=122r   c                2    t        | j                  d         S )z8Return the RC4 or AES encryption key used for this file.encryption_keyr:   r'   s    r   r>   zEncryptionInfo.encryption_key~   s     T]]#3455r   c                8    t        | j                  d         dz  S )z|Return the number of bits in the encryption algorithm.

        e.g. if the algorithm is AES-256, this returns 256.
        r>      )lenr   r'   s    r   bitszEncryptionInfo.bits   s     4==!123a77r   c                    d| j                   j                   d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d| j                  d	| j                  d
| j                  dS )N<z	: self.R=z	, self.V=z	, self.P=z self.stream_method=z, self.string_method=z, self.file_method=z, self.user_password=z, self.encryption_key=z, self.bits=>)	__class__r   r$   r*   r,   r0   r4   r7   r<   r>   rB   r'   s    r   __repr__zEncryptionInfo.__repr__   s    ''(
466):dffYj	 J#!!##9d&8&8%: ;!!!7D$6$6#8 9$""$Mtyyl!5	
r   N)r!   zdict[str, Any])returnr&   )rH   r   )rH   r;   )r   r   r   r   r"   propertyr$   r*   r,   r0   r4   r7   r<   r>   rB   rG   r   r   r   r   r   >   s      ' ' ' ' ' ' A A A A ? ? 
3 
3 6 6 8 8
r   r   c                  p    e Zd ZU dZdZded<   	 dZded<   	 dZded<   	 eZ	d	ed
<   	 dZ
ded<   	 dZded<   y)
Encryptionz=Specify the encryption settings to apply when a PDF is saved. strowneruser   zLiteral[2, 3, 4, 5, 6]r$   r
   allowTr   aesmetadataN)r   r   r   r   rN   r   rO   r$   DEFAULT_PERMISSIONSrQ   rR   rS   r   r   r   rK   rK      sh    GE3O6
 D#N3
 !"A!
 -E;,< C? Hd<r   rK   N)r   
__future__r   typingr   r   r   r   pikepdf._corer   r
   rT   r   rK   r   r   r   <module>rX      sF    # " 1 1 *+;* +;\ "m S
 S
l!< !<r   