Ë
    ¨Œjz¾  ã                   óR  — d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z	m
Z
 d dlmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZm Z m!Z!  G d„ d	«      Z"d
Z#de$de$fd„Z% G d„ d«      Z& G d„ d«      Z' G d„ de«      Z( G d„ de)e«      Z* G d„ d«      Z+ G d„ d«      Z,y)é    N)ÚEnumÚIntEnum)ÚAnyÚOptionalÚUnionÚcast)
ÚCryptAESÚ	CryptBaseÚCryptIdentityÚCryptRC4Úaes_cbc_decryptÚaes_cbc_encryptÚaes_ecb_decryptÚaes_ecb_encryptÚrc4_decryptÚrc4_encrypté   )Úlogger_warning)	ÚArrayObjectÚByteStringObjectÚDictionaryObjectÚ
NameObjectÚNumberObjectÚ	PdfObjectÚStreamObjectÚTextStringObjectÚcreate_string_objectc                   óD   — e Zd Zdedededdfd„Zdedefd„Zdedefd	„Zy)
ÚCryptFilterÚ	stm_cryptÚ	str_cryptÚef_cryptÚreturnNc                 ó.   — || _         || _        || _        y ©N)r    r!   r"   )Úselfr    r!   r"   s       ú[/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/pypdf/_encryption.pyÚ__init__zCryptFilter.__init__=   s   € ð #ˆŒØ"ˆŒØ ˆ�ó    Úobjc                 ó  ‡ — t        |t        «      r2‰ j                  j                  |j                  «      }t        |«      }|S t        |t
        «      r6‰ j                  j                  |j                  «       «      }t        |«      }|S t        |t        «      rt        «       }|j                  |«       |j                  ‰ j                  j                  |j                  «      «       |j                  «       D ]  \  }}‰ j                  |«      ||<   Œ |}|S t        |t        «      r:t        «       }|j                  «       D ]  \  }}‰ j                  |«      ||<   Œ |}|S t        |t        «      rt        ˆ fd„|D «       «      }|S )Nc              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr%   )Úencrypt_object)Ú.0Úxr&   s     €r'   Ú	<genexpr>z-CryptFilter.encrypt_object.<locals>.<genexpr>[   s   øè ø€ ÐB¹c¸˜d×1Ñ1°!×4¹cùs   ƒ)Ú
isinstancer   r!   ÚencryptÚoriginal_bytesr   Úget_encoded_bytesr   ÚupdateÚset_datar    Ú_dataÚitemsr-   r   r   )r&   r*   ÚdataÚobj2ÚkeyÚvalues   `     r'   r-   zCryptFilter.encrypt_objectG   sP  ø€ Ü�cÔ+Ô,Ø—>‘>×)Ñ)¨#×*<Ñ*<Ó=ˆDÜ" 4Ó(ˆCð$ ˆ
ô# ˜Ô-Ô.Ø—>‘>×)Ñ)¨#×*?Ñ*?Ó*AÓBˆDÜ" 4Ó(ˆCð ˆ
ô ˜œ\Ô*Ü“>ˆDØ�K‰K˜ÔØ�M‰M˜$Ÿ.™.×0Ñ0°·±Ó;Ô<Ø!Ÿi™ižk‘
��UØ ×/Ñ/°Ó6��S’	ð *àˆCð ˆ
ô ˜Ô-Ô.Ü#Ó%ˆDØ!Ÿi™ižk‘
��UØ ×/Ñ/°Ó6��S’	ð *àˆCð ˆ
ô ˜œ[Ô)ÜÓB¹cÓBÓBˆCØˆ
r)   c                 ób  — t        |t        t        f«      r2| j                  j	                  |j
                  «      }t        |«      }|S t        |t        «      rX| j                  j	                  |j                  «      |_	        |j                  «       D ]  \  }}| j                  |«      ||<   Œ |S t        |t        «      r.|j                  «       D ]  \  }}| j                  |«      ||<   Œ |S t        |t        «      r0t        t        |«      «      D ]  }| j                  ||   «      ||<   Œ |S r%   )r1   r   r   r!   Údecryptr3   r   r   r    r7   r8   Údecrypt_objectr   r   ÚrangeÚlen)r&   r*   r9   r;   r<   Úis         r'   r?   zCryptFilter.decrypt_object^   s
  € Ü�cÔ,Ô.>Ð?Ô@Ø—>‘>×)Ñ)¨#×*<Ñ*<Ó=ˆDÜ& tÓ,ˆCð ˆ
ô ˜œ\Ô*ØŸ™×.Ñ.¨s¯y©yÓ9ˆCŒIØ!Ÿi™ižk‘
��UØ×.Ñ.¨uÓ5��C’ð *ð ˆ
ô ˜Ô-Ô.Ø!Ÿi™ižk‘
��UØ×.Ñ.¨uÓ5��C’ð *ð
 ˆ
ô ˜œ[Ô)Üœ3˜s›8–_�Ø×,Ñ,¨S°©VÓ4��A’ð %àˆ
r)   )Ú__name__Ú
__module__Ú__qualname__r
   r(   r   r-   r?   © r)   r'   r   r   <   sS   „ ð!àð!ð ð!ð ð	!ð
 
ó!ð )ð °	ó ð. )ð °	ô r)   r   s    (¿N^NuŠAd NVÿú.. ¶Ðh>€/©þdSizr9   r#   c                 ó   — | t         z   d d S )Né    )Ú_PADDING)r9   s    r'   Ú_paddingrJ   u   s   € Ø”8‰O˜S˜bÐ!Ð!r)   c                   ó  — e Zd Zededededededededefd	„«       Zed
edededefd„«       Zededededefd„«       Z	ededededefd„«       Z
edededededededededefd„«       Zed
ededededededededefd„«       Zy)ÚAlgV4ÚpasswordÚrevÚkey_sizeÚo_entryÚPÚ	id1_entryÚmetadata_encryptedr#   c                 óª  — t        | «      }t        j                  |«      }|j                  |«       |j                  t	        j
                  d|«      «       |j                  |«       |dk\  r|s|j                  d«       |j                  «       }	|dz  }
|dk\  r6t        d«      D ](  }t        j                  |	d|
 «      j                  «       }	Œ* |	d|
 S )uÞ  
        Algorithm 2: Computing an encryption key.

        a) Pad or truncate the password string to exactly 32 bytes. If the
           password string is more than 32 bytes long,
           use only its first 32 bytes; if it is less than 32 bytes long, pad it
           by appending the required number of
           additional bytes from the beginning of the following padding string:
                < 28 BF 4E 5E 4E 75 8A 41 64 00 4E 56 FF FA 01 08
                2E 2E 00 B6 D0 68 3E 80 2F 0C A9 FE 64 53 69 7A >
           That is, if the password string is n bytes long, append
           the first 32 - n bytes of the padding string to the end
           of the password string. If the password string is empty
           (zero-length), meaning there is no user password,
           substitute the entire padding string in its place.

        b) Initialize the MD5 hash function and pass the result of step (a)
           as input to this function.
        c) Pass the value of the encryption dictionaryâ€™s O entry to the
           MD5 hash function. ("Algorithm 3: Computing
           the encryption dictionaryâ€™s O (owner password) value" shows how the
           O value is computed.)
        d) Convert the integer value of the P entry to a 32-bit unsigned binary
           number and pass these bytes to the
           MD5 hash function, low-order byte first.
        e) Pass the first element of the fileâ€™s file identifier array (the value
           of the ID entry in the documentâ€™s trailer
           dictionary; see Table 15) to the MD5 hash function.
        f) (Security handlers of revision 4 or greater) If document metadata is
           not being encrypted, pass 4 bytes with
           the value 0xFFFFFFFF to the MD5 hash function.
        g) Finish the hash.
        h) (Security handlers of revision 3 or greater) Do the following
           50 times: Take the output from the previous
           MD5 hash and pass the first n bytes of the output as input into a new
           MD5 hash, where n is the number of
           bytes of the encryption key as defined by the value of the encryption
           dictionaryâ€™s Length entry.
        i) Set the encryption key to the first n bytes of the output from the
           final MD5 hash, where n shall always be 5
           for security handlers of revision 2 but, for security handlers of
           revision 3 or greater, shall depend on the
           value of the encryption dictionaryâ€™s Length entry.

        Args:
            password: The encryption secret as a bytes-string
            rev: The encryption revision (see PDF standard)
            key_size: The size of the key in bytes
            o_entry: The owner entry
            P: A set of flags specifying which operations shall be permitted
                when the document is opened with user access. If bit 2 is set to 1,
                all other bits are ignored and all operations are permitted.
                If bit 2 is set to 0, permission for operations are based on the
                values of the remaining flags defined in Table 24.
            id1_entry:
            metadata_encrypted: A boolean indicating if the metadata is encrypted.

        Returns:
            The u_hash digest of length key_size

        ú<Ié   ó   ÿÿÿÿé   é   é2   N)rJ   ÚhashlibÚmd5r5   ÚstructÚpackÚdigestr@   )rM   rN   rO   rP   rQ   rR   rS   ÚaÚu_hashÚu_hash_digestÚlengthÚ_s               r'   Úcompute_keyzAlgV4.compute_keyz   s¶   € ôN �XÓˆÜ—‘˜Q“ˆØ�‰�gÔØ�‰”f—k‘k $¨Ó*Ô+Ø�‰�iÔ Ø�!Š8Ñ.Ø�M‰MÐ-Ô.ØŸ™›ˆØ˜Q‘ˆØ�!Š8Ü˜2–Y�Ü '§¡¨M¸'¸6Ð,BÓ C× JÑ JÓ L‘ð à˜W˜fÐ%Ð%r)   Úowner_passwordc                 óÞ   — t        | «      }t        j                  |«      j                  «       }|dk\  r3t	        d«      D ]%  }t        j                  |«      j                  «       }Œ' |d|dz   S )u  
        Algorithm 3: Computing the encryption dictionaryâ€™s O (owner password) value.

        a) Pad or truncate the owner password string as described in step (a)
           of "Algorithm 2: Computing an encryption key".
           If there is no owner password, use the user password instead.
        b) Initialize the MD5 hash function and pass the result of step (a) as
           input to this function.
        c) (Security handlers of revision 3 or greater) Do the following 50 times:
           Take the output from the previous
           MD5 hash and pass it as input into a new MD5 hash.
        d) Create an RC4 encryption key using the first n bytes of the output
           from the final MD5 hash, where n shall
           always be 5 for security handlers of revision 2 but, for security
           handlers of revision 3 or greater, shall
           depend on the value of the encryption dictionaryâ€™s Length entry.
        e) Pad or truncate the user password string as described in step (a) of
           "Algorithm 2: Computing an encryption key".
        f) Encrypt the result of step (e), using an RC4 encryption function with
           the encryption key obtained in step (d).
        g) (Security handlers of revision 3 or greater) Do the following 19 times:
           Take the output from the previous
           invocation of the RC4 function and pass it as input to a new
           invocation of the function; use an encryption
           key generated by taking each byte of the encryption key obtained in
           step (d) and performing an XOR
           (exclusive or) operation between that byte and the single-byte value
           of the iteration counter (from 1 to 19).
        h) Store the output from the final invocation of the RC4 function as
           the value of the O entry in the encryption dictionary.

        Args:
            owner_password:
            rev: The encryption revision (see PDF standard)
            key_size: The size of the key in bytes

        Returns:
            The RC4 key

        rY   rZ   NrX   )rJ   r[   r\   r_   r@   )rf   rN   rO   r`   Úo_hash_digestrd   s         r'   Úcompute_O_value_keyzAlgV4.compute_O_value_keyÏ   sd   € ôT �^Ó$ˆÜŸ™ A›×-Ñ-Ó/ˆà�!Š8Ü˜2–Y�Ü '§¡¨MÓ :× AÑ AÓ C‘ð ð ˜_˜x¨1™}Ð-Ð-r)   Úrc4_keyÚuser_passwordc                 ó¢   ‡— t        |«      }t        | |«      }|dk\  r1t        dd«      D ]"  Št        ˆfd„| D «       «      }t        ||«      }Œ$ |S )zÞ
        See :func:`compute_O_value_key`.

        Args:
            rc4_key:
            user_password:
            rev: The encryption revision (see PDF standard)

        Returns:
            The RC4 encrypted

        rY   r   é   c              3   ó(   •K  — | ]	  }|‰z  –— Œ y ­wr%   rF   ©r.   r/   rB   s     €r'   r0   z(AlgV4.compute_O_value.<locals>.<genexpr>  ó   øè ø€ Ð3©7 a˜A �E©7ùó   ƒ)rJ   r   r@   Úbytes)rj   rk   rN   r`   Úrc4_encr;   rB   s         @r'   Úcompute_O_valuezAlgV4.compute_O_value  sU   ø€ ô �]Ó#ˆÜ˜g qÓ)ˆØ�!Š8Ü˜1˜b–\�ÜÓ3©7Ó3Ó3�Ü% c¨7Ó3‘ð "ð ˆr)   r;   c                 ó0  ‡— |dk  rt        | t        «      S 	 t        j                  t        «      }|j	                  |«       t        | |j                  «       «      }t        dd«      D ]"  Št        ˆfd„| D «       «      }t        ||«      }Œ$ t        |«      S )uù  
        Algorithm 4: Computing the encryption dictionaryâ€™s U (user password) value.

        (Security handlers of revision 2)

        a) Create an encryption key based on the user password string, as
           described in "Algorithm 2: Computing an encryption key".
        b) Encrypt the 32-byte padding string shown in step (a) of
           "Algorithm 2: Computing an encryption key", using an RC4 encryption
           function with the encryption key from the preceding step.
        c) Store the result of step (b) as the value of the U entry in the
           encryption dictionary.

        Args:
            key:
            rev: The encryption revision (see PDF standard)
            id1_entry:

        Returns:
            The value

        é   r   rm   c              3   ó(   •K  — | ]	  }|‰z  –— Œ y ­wr%   rF   ro   s     €r'   r0   z(AlgV4.compute_U_value.<locals>.<genexpr>P  s   øè ø€ Ð/©3 a˜A �E©3ùrq   )	r   rI   r[   r\   r5   r_   r@   rr   rJ   )r;   rN   rR   ra   rs   rj   rB   s         @r'   Úcompute_U_valuezAlgV4.compute_U_value  s…   ø€ ð0 �!Š8Ü˜s¤HÓ-Ð-ð	ô2 —‘œXÓ&ˆØ�‰�iÔ Ü˜c 6§=¡=£?Ó3ˆÜ�q˜"–ˆAÜÓ/©3Ó/Ó/ˆGÜ! '¨7Ó3‰Gð ô ˜Ó Ð r)   Úu_entryc           	      ó–   — t         j                  | ||||||«      }t         j                  |||«      }	|dk\  r
|	dd }	|dd }|	|k7  rd}|S )ur  
        Algorithm 6: Authenticating the user password.

        a) Perform all but the last step of "Algorithm 4: Computing the
           encryption dictionaryâ€™s U (user password) value (Security handlers of
           revision 2)" or "Algorithm 5: Computing the encryption dictionaryâ€™s U
           (user password) value (Security handlers of revision 3 or greater)"
           using the supplied password string.
        b) If the result of step (a) is equal to the value of the encryption
           dictionaryâ€™s U entry (comparing on the first 16 bytes in the case of
           security handlers of revision 3 or greater), the password supplied is
           the correct user password. The key obtained in step (a) (that is, in
           the first step of "Algorithm 4: Computing the encryption
           dictionaryâ€™s U (user password) value
           (Security handlers of revision 2)" or
           "Algorithm 5: Computing the encryption dictionaryâ€™s U (user password)
           value (Security handlers of revision 3 or greater)") shall be used
           to decrypt the document.

        Args:
            user_password: The user password as a bytes stream
            rev: The encryption revision (see PDF standard)
            key_size: The size of the key in bytes
            o_entry: The owner entry
            u_entry: The user entry
            P: A set of flags specifying which operations shall be permitted
                when the document is opened with user access. If bit 2 is set to 1,
                all other bits are ignored and all operations are permitted.
                If bit 2 is set to 0, permission for operations are based on the
                values of the remaining flags defined in Table 24.
            id1_entry:
            metadata_encrypted: A boolean indicating if the metadata is encrypted.

        Returns:
            The key

        rY   Né   r)   )rL   re   rx   )
rk   rN   rO   rP   ry   rQ   rR   rS   r;   Úu_values
             r'   Úverify_user_passwordzAlgV4.verify_user_passwordT  sj   € ô` ×ÑØ˜3 ¨'°1°iÐASó
ˆô ×'Ñ'¨¨S°)Ó<ˆØ�!Š8Ø˜c˜r�lˆGØ˜c˜r�lˆGØ�gÒØˆCØˆ
r)   c           
      óö   ‡— t         j                  | ||«      }|dk  rt        ||«      }	n4|}	t        ddd«      D ]"  Št	        ˆfd„|D «       «      }
t        |
|	«      }	Œ$ t         j                  |	|||||||«      S )uN  
        Algorithm 7: Authenticating the owner password.

        a) Compute an encryption key from the supplied password string, as
           described in steps (a) to (d) of
           "Algorithm 3: Computing the encryption dictionaryâ€™s O (owner password)
           value".
        b) (Security handlers of revision 2 only) Decrypt the value of the
           encryption dictionaryâ€™s O entry, using an RC4
           encryption function with the encryption key computed in step (a).
           (Security handlers of revision 3 or greater) Do the following 20 times:
           Decrypt the value of the encryption dictionaryâ€™s O entry (first iteration)
           or the output from the previous iteration (all subsequent iterations),
           using an RC4 encryption function with a different encryption key at
           each iteration. The key shall be generated by taking the original key
           (obtained in step (a)) and performing an XOR (exclusive or) operation
           between each byte of the key and the single-byte value of the
           iteration counter (from 19 to 0).
        c) The result of step (b) purports to be the user password.
           Authenticate this user password using
           "Algorithm 6: Authenticating the user password".
           If it is correct, the password supplied is the correct owner password.

        Args:
            owner_password:
            rev: The encryption revision (see PDF standard)
            key_size: The size of the key in bytes
            o_entry: The owner entry
            u_entry: The user entry
            P: A set of flags specifying which operations shall be permitted
                when the document is opened with user access. If bit 2 is set to 1,
                all other bits are ignored and all operations are permitted.
                If bit 2 is set to 0, permission for operations are based on the
                values of the remaining flags defined in Table 24.
            id1_entry:
            metadata_encrypted: A boolean indicating if the metadata is encrypted.

        Returns:
            bytes

        rv   é   éÿÿÿÿc              3   ó(   •K  — | ]	  }|‰z  –— Œ y ­wr%   rF   ro   s     €r'   r0   z.AlgV4.verify_owner_password.<locals>.<genexpr>Ê  rp   rq   )rL   ri   r   r@   rr   r}   )rf   rN   rO   rP   ry   rQ   rR   rS   rj   rk   r;   rB   s              @r'   Úverify_owner_passwordzAlgV4.verify_owner_password�  sŽ   ø€ ôh ×+Ñ+¨N¸CÀÓJˆà�!Š8Ü'¨°Ó9‰Mà#ˆMÜ˜2˜r 2Ö&�ÜÓ3©7Ó3Ó3�Ü +¨C°Ó ?‘ð 'ô ×)Ñ)ØØØØØØØØó	
ð 		
r)   N)rC   rD   rE   Ústaticmethodrr   ÚintÚboolre   ri   rt   rx   r}   r‚   rF   r)   r'   rL   rL   y   sÝ  „ ØðR&ØðR&àðR&ð ðR&ð ð	R&ð
 ðR&ð ðR&ð !ðR&ð 
òR&ó ðR&ðh ð0.¨Eð 0.¸ð 0.Àsð 0.Èuò 0.ó ð0.ðd ð ð °uð À3ð È5ò ó ðð* ð9!˜Uð 9!¨ð 9!¸ð 9!À5ò 9!ó ð9!ðv ð8Øð8àð8ð ð8ð ð	8ð
 ð8ð ð8ð ð8ð !ð8ð 
ò8ó ð8ðt ðE
ØðE
àðE
ð ðE
ð ð	E
ð
 ðE
ð ðE
ð ðE
ð !ðE
ð 
òE
ó ñE
r)   rL   c                   ó^  — e Zd Zededededededefd„«       Zedededededef
d	„«       Zededed
ededef
d„«       Zedededede	de	f
d„«       Z
edededededede	deeef   fd„«       Zededededeeef   fd„«       Zedededededeeef   f
d„«       Zededede	defd„«       Zy)ÚAlgV5ÚRrM   Úo_valueÚoe_valuer|   r#   c                 óâ   — |dd }t         j                  | ||dd |dd «      |dd k7  ryt        d„ t        d«      D «       «      }t         j                  | ||dd |dd «      }t	        |||«      S )	u  
        Algorithm 3.2a Computing an encryption key.

        To understand the algorithm below, it is necessary to treat the O and U
        strings in the Encrypt dictionary as made up of three sections.
        The first 32 bytes are a hash value (explained below). The next 8 bytes
        are called the Validation Salt. The final 8 bytes are called the Key Salt.

        1. The password string is generated from Unicode input by processing the
           input string with the SASLprep (IETF RFC 4013) profile of
           stringprep (IETF RFC 3454), and then converting to a UTF-8
           representation.
        2. Truncate the UTF-8 representation to 127 bytes if it is longer than
           127 bytes.
        3. Test the password against the owner key by computing the SHA-256 hash
           of the UTF-8 password concatenated with the 8 bytes of owner
           Validation Salt, concatenated with the 48-byte U string. If the
           32-byte result matches the first 32 bytes of the O string, this is
           the owner password.
           Compute an intermediate owner key by computing the SHA-256 hash of
           the UTF-8 password concatenated with the 8 bytes of owner Key Salt,
           concatenated with the 48-byte U string. The 32-byte result is the
           key used to decrypt the 32-byte OE string using AES-256 in CBC mode
           with no padding and an initialization vector of zero.
           The 32-byte result is the file encryption key.
        4. Test the password against the user key by computing the SHA-256 hash
           of the UTF-8 password concatenated with the 8 bytes of user
           Validation Salt. If the 32 byte result matches the first 32 bytes of
           the U string, this is the user password.
           Compute an intermediate user key by computing the SHA-256 hash of the
           UTF-8 password concatenated with the 8 bytes of user Key Salt.
           The 32-byte result is the key used to decrypt the 32-byte
           UE string using AES-256 in CBC mode with no padding and an
           initialization vector of zero. The 32-byte result is the file
           encryption key.
        5. Decrypt the 16-byte Perms string using AES-256 in ECB mode with an
           initialization vector of zero and the file encryption key as the key.
           Verify that bytes 9-11 of the result are the characters â€˜aâ€™, â€˜dâ€™, â€˜bâ€™.
           Bytes 0-3 of the decrypted Perms entry, treated as a little-endian
           integer, are the user permissions.
           They should match the value in the P key.

        Args:
            R: A number specifying which revision of the standard security
                handler shall be used to interpret this dictionary
            password: The owner password
            o_value: A 32-byte string, based on both the owner and user passwords,
                that shall be used in computing the encryption key and in
                determining whether a valid owner password was entered
            oe_value:
            u_value: A 32-byte string, based on the user password, that shall be
                used in determining whether to prompt the user for a password and,
                if so, whether a valid user or owner password was entered.

        Returns:
            The key

        Né   rH   é(   é0   r)   c              3   ó    K  — | ]  }d –— Œ y­w©r   NrF   ©r.   rd   s     r'   r0   z.AlgV5.verify_owner_password.<locals>.<genexpr>  ó   è ø€ Ð(™i˜”1™iùó   ‚r{   ©r‡   Úcalculate_hashrr   r@   r   )rˆ   rM   r‰   rŠ   r|   ÚivÚtmp_keys          r'   r‚   zAlgV5.verify_owner_passwordÙ  sˆ   € ð| ˜D˜S�>ˆä× Ñ   H¨g°b¸¨n¸gÀcÀr¸lÓKØ�s˜ˆ|òð ÜÑ(œe BœiÓ(Ó(ˆÜ×&Ñ& q¨(°G¸B¸r°NÀGÈCÈRÀLÓQˆÜ˜w¨¨HÓ5Ð5r)   Úue_valuec                 óÖ   — |dd }t         j                  | ||dd d«      |dd k7  ryt        d„ t        d«      D «       «      }t         j                  | ||dd d«      }t	        |||«      S )	a#  
        See :func:`verify_owner_password`.

        Args:
            R: A number specifying which revision of the standard security
                handler shall be used to interpret this dictionary
            password: The user password
            u_value: A 32-byte string, based on the user password, that shall be
                used in determining whether to prompt the user for a password
                and, if so, whether a valid user or owner password was entered.
            ue_value:

        Returns:
            bytes

        NrŒ   rH   r�   r)   c              3   ó    K  — | ]  }d –— Œ y­wr�   rF   r‘   s     r'   r0   z-AlgV5.verify_user_password.<locals>.<genexpr>8  r’   r“   r{   rŽ   r”   )rˆ   rM   r|   r˜   r–   r—   s         r'   r}   zAlgV5.verify_user_password!  sv   € ð( ˜D˜S�>ˆÜ×Ñ  8¨W°R¸¨^¸SÓAÀWÈSÈbÀ\ÒQØÜÑ(œe BœiÓ(Ó(ˆÜ×&Ñ& q¨(°G¸B¸r°NÀCÓHˆÜ˜w¨¨HÓ5Ð5r)   ÚsaltÚudatac                 óŠ  — t        j                  ||z   |z   «      j                  «       }| dk  r|S d}	 |dz  }||z   |z   }t        |d d |dd |dz  «      }t         j                  t         j                  t         j
                  ft        |d d «      dz     } ||«      j                  «       }|dk\  r|d   |dz
  k  rnŒŒ|d d S )	Né   r   r   r{   rH   é@   rY   r€   )r[   Úsha256r_   r   Úsha384Úsha512Úsum)	rˆ   rM   r›   rœ   ÚkÚcountÚk1ÚeÚhash_fns	            r'   r•   zAlgV5.calculate_hash<  sà   € ô �N‰N˜8 d™?¨UÑ2Ó3×:Ñ:Ó<ˆØˆqŠ5ØˆHØˆØØ�Q‰JˆEØ˜A‘ Ñ%ˆBÜ  # 2 ¨¨"¨R¨°"°r±'Ó:ˆAä—‘Ü—‘Ü—‘ðô �!�C�R�&‹k˜A‰oñ	ˆGñ
 ˜“
×!Ñ!Ó#ˆAØ˜Š{˜q ™u¨°©
Ò2Øð ð ��"ˆvˆr)   r;   ÚpermsÚprS   c                 ót   — |rdnd}t        j                  d|«      dz   |z   dz   }t        | |«      }||dd k(  S )au  
        See :func:`verify_owner_password` and :func:`compute_perms_value`.

        Args:
            key: The owner password
            perms:
            p: A set of flags specifying which operations shall be permitted
                when the document is opened with user access.
                If bit 2 is set to 1, all other bits are ignored and all
                operations are permitted.
                If bit 2 is set to 0, permission for operations are based on
                the values of the remaining flags defined in Table 24.
            metadata_encrypted:

        Returns:
            A boolean

        ó   Tó   FrU   rW   ó   adbNé   )r]   r^   r   )r;   r©   rª   rS   Úb8Úp1Úp2s          r'   Úverify_permszAlgV5.verify_permsQ  sI   € ñ, (‰T¨TˆÜ�[‰[˜˜qÓ!Ð$7Ñ7¸"Ñ<¸vÑEˆÜ˜S %Ó(ˆØ�R˜˜�W‰}Ðr)   rk   rf   c                 ó¾   — |d d }|d d }t         j                  | ||«      \  }}t         j                  | |||«      \  }}	t         j                  |||«      }
||||	|
dœS )NrŒ   )ú/Uú/UEú/Oú/OEú/Perms)r‡   rx   rt   Úcompute_Perms_value)rˆ   rk   rf   r;   rª   rS   r|   r˜   r‰   rŠ   r©   s              r'   Úgenerate_valueszAlgV5.generate_valuesl  s~   € ð & d sÐ+ˆØ'¨¨Ð-ˆÜ!×1Ñ1°!°]ÀCÓHÑˆ�Ü!×1Ñ1°!°^ÀSÈ'ÓRÑˆ�Ü×)Ñ)¨#¨qÐ2DÓEˆàØØØØñ
ð 	
r)   c                 ó  — t        j                  d«      }|dd }|dd }t        j                  | ||d«      |z   |z   }t        j                  | ||d«      }t	        d„ t        d«      D «       «      }t        |||«      }	||	fS )u%  
        Algorithm 3.8 Computing the encryption dictionaryâ€™s U (user password)
        and UE (user encryption key) values.

        1. Generate 16 random bytes of data using a strong random number generator.
           The first 8 bytes are the User Validation Salt. The second 8 bytes
           are the User Key Salt. Compute the 32-byte SHA-256 hash of the
           password concatenated with the User Validation Salt. The 48-byte
           string consisting of the 32-byte hash followed by the User
           Validation Salt followed by the User Key Salt is stored as the U key.
        2. Compute the 32-byte SHA-256 hash of the password concatenated with
           the User Key Salt. Using this hash as the key, encrypt the file
           encryption key using AES-256 in CBC mode with no padding and an
           initialization vector of zero. The resulting 32-byte string is stored
           as the UE key.

        Args:
            R:
            password:
            key:

        Returns:
            A tuple (u-value, ue value)

        r{   NrX   r)   c              3   ó    K  — | ]  }d –— Œ y­wr�   rF   r‘   s     r'   r0   z(AlgV5.compute_U_value.<locals>.<genexpr>£  r’   r“   ©ÚsecretsÚtoken_bytesr‡   r•   rr   r@   r   )
rˆ   rM   r;   Úrandom_bytesÚval_saltÚkey_saltr|   r—   r–   r˜   s
             r'   rx   zAlgV5.compute_U_value‚  s�   € ô6 ×*Ñ*¨2Ó.ˆØ  Ð#ˆØ  Ð#ˆÜ×&Ñ& q¨(°H¸cÓBÀXÑMÐPXÑXˆä×&Ñ& q¨(°H¸cÓBˆÜÑ(œe BœiÓ(Ó(ˆÜ" 7¨B°Ó4ˆØ˜Ð Ð r)   c                 ó
  — t        j                  d«      }|dd }|dd }t        j                  | |||«      |z   |z   }t        j                  | |||dd «      }t	        d„ t        d«      D «       «      }	t        ||	|«      }
||
fS )uÙ  
        Algorithm 3.9 Computing the encryption dictionaryâ€™s O (owner password)
        and OE (owner encryption key) values.

        1. Generate 16 random bytes of data using a strong random number
           generator. The first 8 bytes are the Owner Validation Salt. The
           second 8 bytes are the Owner Key Salt. Compute the 32-byte SHA-256
           hash of the password concatenated with the Owner Validation Salt and
           then concatenated with the 48-byte U string as generated in
           Algorithm 3.8. The 48-byte string consisting of the 32-byte hash
           followed by the Owner Validation Salt followed by the Owner Key Salt
           is stored as the O key.
        2. Compute the 32-byte SHA-256 hash of the password concatenated with
           the Owner Key Salt and then concatenated with the 48-byte U string as
           generated in Algorithm 3.8. Using this hash as the key,
           encrypt the file encryption key using AES-256 in CBC mode with
           no padding and an initialization vector of zero.
           The resulting 32-byte string is stored as the OE key.

        Args:
            R:
            password:
            key:
            u_value: A 32-byte string, based on the user password, that shall be
                used in determining whether to prompt the user for a password
                and, if so, whether a valid user or owner password was entered.

        Returns:
            A tuple (O value, OE value)

        r{   NrX   rŽ   c              3   ó    K  — | ]  }d –— Œ y­wr�   rF   r‘   s     r'   r0   z(AlgV5.compute_O_value.<locals>.<genexpr>Ñ  r’   r“   r¾   )rˆ   rM   r;   r|   rÁ   rÂ   rÃ   r‰   r—   r–   rŠ   s              r'   rt   zAlgV5.compute_O_value§  s›   € ôF ×*Ñ*¨2Ó.ˆØ  Ð#ˆØ  Ð#ˆä× Ñ   H¨h¸Ó@À8ÑKÈhÑVð 	ô ×&Ñ& q¨(°H¸gÀcÀr¸lÓKˆÜÑ(œe BœiÓ(Ó(ˆÜ" 7¨B°Ó4ˆØ˜Ð Ð r)   c                 ó”   — |rdnd}t        j                  d«      }t        j                  d|«      dz   |z   dz   |z   }t	        | |«      S )uß  
        Algorithm 3.10 Computing the encryption dictionaryâ€™s Perms
        (permissions) value.

        1. Extend the permissions (contents of the P integer) to 64 bits by
           setting the upper 32 bits to all 1â€™s.
           (This allows for future extension without changing the format.)
        2. Record the 8 bytes of permission in the bytes 0-7 of the block,
           low order byte first.
        3. Set byte 8 to the ASCII value ' T ' or ' F ' according to the
           EncryptMetadata Boolean.
        4. Set bytes 9-11 to the ASCII characters ' a ', ' d ', ' b '.
        5. Set bytes 12-15 to 4 bytes of random data, which will be ignored.
        6. Encrypt the 16-byte block using AES-256 in ECB mode with an
           initialization vector of zero, using the file encryption key as the
           key. The result (16 bytes) is stored as the Perms string, and checked
           for validity when the file is opened.

        Args:
            key:
            p: A set of flags specifying which operations shall be permitted
                when the document is opened with user access. If bit 2 is set to 1,
                all other bits are ignored and all operations are permitted.
                If bit 2 is set to 0, permission for operations are based on the
                values of the remaining flags defined in Table 24.
            metadata_encrypted: A boolean indicating if the metadata is encrypted.

        Returns:
            The perms value

        r¬   r­   rV   rU   rW   r®   )r¿   rÀ   r]   r^   r   )r;   rª   rS   r°   Úrrr9   s         r'   rº   zAlgV5.compute_Perms_valueÕ  sP   € ñB (‰T¨TˆÜ× Ñ  Ó#ˆÜ�{‰{˜4 Ó#Ð&9Ñ9¸BÑ>ÀÑGÈ"ÑLˆÜ˜s DÓ)Ð)r)   N)rC   rD   rE   rƒ   r„   rr   r‚   r}   r•   r…   r³   Údictr   r»   Útuplerx   rt   rº   rF   r)   r'   r‡   r‡   Ø  s
  „ ØðE6ØðE6ØðE6Ø*/ðE6Ø;@ðE6ØKPðE6à	òE6ó ðE6ðN ð6Øð6Øð6Ø*/ð6Ø;@ð6à	ò6ó ð6ð4 ð˜#ð ¨ð °eð ÀEð Èeò ó ðð( ðØðØ ðØ%(ðØ>Bðà	òó ðð4 ð
Øð
àð
ð ð
ð ð	
ð
 ð
ð !ð
ð 
ˆc�3ˆh‰ò
ó ð
ð* ð"!˜3ð "!¨%ð "!°eð "!ÀÀeÈUÀlÑ@Sò "!ó ð"!ðH ð+!Øð+!Øð+!Ø&+ð+!Ø6;ð+!à	ˆu�eˆ|Ñ	ò+!ó ð+!ðZ ð#* ð #*¨3ð #*ÀDð #*ÈUò #*ó ñ#*r)   r‡   c                   ó   — e Zd ZdZdZdZy)ÚPasswordTyper   r   rv   N)rC   rD   rE   ÚNOT_DECRYPTEDÚUSER_PASSWORDÚOWNER_PASSWORDrF   r)   r'   rË   rË   ü  s   „ Ø€MØ€MØ�Nr)   rË   c                   ó    — e Zd ZdZdZdZdZdZy)ÚEncryptAlgorithm)r   rv   r�   )rv   rY   é€   )rV   rV   rÑ   )é   rÒ   é   )rÒ   rž   rÓ   N)rC   rD   rE   ÚRC4_40ÚRC4_128ÚAES_128Ú
AES_256_R5ÚAES_256rF   r)   r'   rÐ   rÐ     s   „ à€FØ€GØ€GØ€JØ�Gr)   rÐ   c                   ó@   — e Zd ZU eed<   eed<   eed<   eed<   eed<   y)ÚEncryptionValuesÚOÚUÚOEÚUEÚPermsN)rC   rD   rE   rr   Ú__annotations__rF   r)   r'   rÚ   rÚ     s   … ØƒHØƒHØƒIØƒIØ„Lr)   rÚ   c                   ó¾  — e Zd ZdZdededededededed	ed
edede	e
   ddfd„Zdefd„Zdedededefd„Zdedededefd„Zededefd„«       Zdededefd„Zedededededef
d„«       Zedeeef   defd„«       Zdeeef   defd„Zdedeeef   fd „Zdedeeef   fd!„Zd"ed#e	e   defd$„Zd"ed#eddfd%„Zed&ededd fd'„«       Zed(e d)ededd fd*„«       Z!y)+Ú
EncryptionaJ  
    Collects and manages parameters for PDF document encryption and decryption.

    Args:
        V: A code specifying the algorithm to be used in encrypting and
           decrypting the document.
        R: The revision of the standard security handler.
        Length: The length of the encryption key in bits.
        P: A set of flags specifying which operations shall be permitted
           when the document is opened with user access
        entry: The encryption dictionary object.
        EncryptMetadata: Whether to encrypt metadata in the document.
        first_id_entry: The first 16 bytes of the file's original ID.
        StmF: The name of the crypt filter that shall be used by default
              when decrypting streams.
        StrF: The name of the crypt filter that shall be used when decrypting
              all strings in the document.
        EFF: The name of the crypt filter that shall be used when
             encrypting embedded file streams that do not have their own
             crypt filter specifier.
        values: Additional encryption parameters.

    ÚVrˆ   ÚLengthrQ   ÚentryÚEncryptMetadataÚfirst_id_entryÚStmFÚStrFÚEFFÚvaluesr#   Nc                 óì   — || _         || _        || _        |dz   dz  | _        || _        || _        || _        |	| _        |
| _        |r|n	t        «       | _
        t        j                  | _        d | _        y )Nl        )rã   rˆ   rä   rQ   ræ   rR   rè   ré   rê   rÚ   rë   rË   rÌ   Ú_password_typeÚ_key)r&   rã   rˆ   rä   rQ   rå   ræ   rç   rè   ré   rê   rë   s               r'   r(   zEncryption.__init__,  sq   € ð  ˆŒØˆŒØˆŒØ�k‘/ [Ñ0ˆŒØ.ˆÔØ'ˆŒØˆŒ	ØˆŒ	ØˆŒÙ28©Ô>NÓ>PˆŒä*×8Ñ8ˆÔØ%)ˆ�	r)   c                 ó<   — | j                   t        j                  k7  S r%   )rí   rË   rÌ   )r&   s    r'   Úis_decryptedzEncryption.is_decryptedJ  s   € Ø×"Ñ"¤l×&@Ñ&@Ñ@Ð@r)   r*   ÚidnumÚ
generationc                 ón   — | j                  |«      s|S | j                  ||«      }|j                  |«      S r%   )Ú_is_encryption_objectÚ_make_crypt_filterr-   ©r&   r*   rñ   rò   Úcfs        r'   r-   zEncryption.encrypt_objectM  ó8   € à×)Ñ)¨#Ô.ØˆJà×$Ñ$ U¨JÓ7ˆØ× Ñ  Ó%Ð%r)   c                 ón   — | j                  |«      s|S | j                  ||«      }|j                  |«      S r%   )rô   rõ   r?   rö   s        r'   r?   zEncryption.decrypt_objectU  rø   r)   c                 óL   — t        | t        t        t        t        t
        f«      S r%   )r1   r   r   r   r   r   )r*   s    r'   rô   z Encryption._is_encryption_object]  s&   € äØä Ü ÜÜÜ ðó	
ð 		
r)   c                 óŽ  — t        j                  d|«      dd }t        j                  d|«      dd }| j                  sJ ‚| j                  }| j                  dk(  rdn| j                  dz  }|d| |z   |z   }t        j                  |«      }|j                  «       dt        |dz   d«       }	|j                  d	«       |j                  «       dt        |dz   d«       }
|}| j                  | j                  |	|
|«      }| j                  | j                  |	|
|«      }| j                  | j                  |	|
|«      }t        |||«      S )
ué	  
        Algorithm 1: Encryption of data using the RC4 or AES algorithms.

        a) Obtain the object number and generation number from the object
           identifier of the string or stream to be encrypted
           (see 7.3.10, "Indirect Objects"). If the string is a direct object,
           use the identifier of the indirect object containing it.
        b) For all strings and streams without crypt filter specifier; treating
           the object number and generation number as binary integers, extend
           the original n-byte encryption key to n + 5 bytes by appending the
           low-order 3 bytes of the object number and the low-order 2 bytes of
           the generation number in that order, low-order byte first.
           (n is 5 unless the value of V in the encryption dictionary is greater
           than 1, in which case n is the value of Length divided by 8.)
           If using the AES algorithm, extend the encryption key an additional
           4 bytes by adding the value â€œsAlTâ€�, which corresponds to the
           hexadecimal values 0x73, 0x41, 0x6C, 0x54. (This addition is done for
           backward compatibility and is not intended to provide additional
           security.)
        c) Initialize the MD5 hash function and pass the result of step (b) as
           input to this function.
        d) Use the first (n + 5) bytes, up to a maximum of 16, of the output
           from the MD5 hash as the key for the RC4 or AES symmetric key
           algorithms, along with the string or stream data to be encrypted.
           If using the AES algorithm, the Cipher Block Chaining (CBC) mode,
           which requires an initialization vector, is used. The block size
           parameter is set to 16 bytes, and the initialization vector is a
           16-byte random number that is stored as the first 16 bytes of the
           encrypted stream or string.

        Algorithm 3.1a Encryption of data using the AES algorithm
        1. Use the 32-byte file encryption key for the AES-256 symmetric key
           algorithm, along with the string or stream data to be encrypted.
           Use the AES algorithm in Cipher Block Chaining (CBC) mode, which
           requires an initialization vector. The block size parameter is set to
           16 bytes, and the initialization vector is a 16-byte random number
           that is stored as the first 16 bytes of the encrypted stream or string.
           The output is the encrypted data to be stored in the PDF file.
        z<iNrY   rv   r   rÒ   rX   r{   s   sAlT)r]   r^   rî   rã   rä   r[   r\   r_   Úminr5   Ú
_get_cryptrè   ré   rê   r   )r&   rñ   rò   Úpack1Úpack2r;   ÚnÚkey_dataÚkey_hashrj   Ú
aes128_keyÚ
aes256_keyr    r!   r"   s                  r'   rõ   zEncryption._make_crypt_filterj  s,  € ôP —‘˜D %Ó(¨¨!Ð,ˆÜ—‘˜D *Ó-¨b¨qÐ1ˆà�yŠyÐˆyØ�i‰iˆØ—‘˜1’‰A $§+¡+°Ñ"2ˆØ�r˜�7˜U‘? UÑ*ˆÜ—;‘;˜xÓ(ˆØ—/‘/Ó#Ð$4¤c¨!¨a©%°£nÐ5ˆð 	�‰˜Ô Ø—_‘_Ó&Ð'7¬¨Q°©U°B«Ð8ˆ
ð ˆ
à—O‘O D§I¡I¨w¸
ÀJÓOˆ	Ø—O‘O D§I¡I¨w¸
ÀJÓOˆ	Ø—?‘? 4§8¡8¨W°jÀ*ÓMˆä˜9 i°Ó:Ð:r)   Úmethodrj   r  r  c                 óv   — | dk(  rt        |«      S | dk(  rt        |«      S | dk(  r
t        «       S t        |«      S )Nú/AESV2ú/AESV3ú	/Identity)r	   r   r   )r  rj   r  r  s       r'   rý   zEncryption._get_crypt©  sE   € ð �XÒÜ˜JÓ'Ð'Ø�XÒÜ˜JÓ'Ð'Ø�[Ò Ü “?Ð"ä˜Ó Ð r)   rM   c                 ó”   — t        | t        «      r	 | j                  d«      }|S | }|S # t        $ r | j                  d«      }Y |S w xY w)Nzlatin-1zutf-8)r1   ÚstrÚencodeÚ	Exception)rM   Úpwds     r'   Ú_encode_passwordzEncryption._encode_password¶  sX   € ä�h¤Ô$ð/Ø—o‘o iÓ0�ð
 ˆ
ð ˆCØˆ
øô	 ò /Ø—o‘o gÓ.‘ð ˆ
ð	/ús   ’) ©AÁAc                 óÒ   — | j                  |«      }| j                  dk  r| j                  |«      n| j                  |«      \  }}|t        j
                  k7  r|| _        || _        |S )NrV   )r  rã   Ú	verify_v4Ú	verify_v5rË   rÌ   rí   rî   )r&   rM   r  r;   Úrcs        r'   ÚverifyzEncryption.verifyÁ  s[   € Ø×#Ñ# HÓ-ˆØ)-¯©°1ª�$—.‘. Ô%¸$¿.¹.ÈÓ:M‰ˆˆRØ”×+Ñ+Ò+Ø"$ˆDÔØˆDŒIØˆ	r)   c           
      óN  — t         j                  || j                  | j                  | j                  j
                  | j                  j                  | j                  | j                  | j                  «      }|r|t        j                  fS t         j                  || j                  | j                  | j                  j
                  | j                  j                  | j                  | j                  | j                  «      }|r|t        j                  fS dt        j                  fS )Nr)   )rL   r‚   rˆ   rä   rë   rÛ   rÜ   rQ   rR   ræ   rË   rÎ   r}   rÍ   rÌ   )r&   rM   r;   s      r'   r  zEncryption.verify_v4É  sÛ   € ä×)Ñ)ØØ�F‰FØ�K‰KØ�K‰K�M‰MØ�K‰K�M‰MØ�F‰FØ�N‰NØ× Ñ ó	
ˆñ Øœ×3Ñ3Ð3Ð3Ü×(Ñ(ØØ�F‰FØ�K‰KØ�K‰K�M‰MØ�K‰K�M‰MØ�F‰FØ�N‰NØ× Ñ ó	
ˆñ Øœ×2Ñ2Ð2Ð2Ø”L×.Ñ.Ð.Ð.r)   c                 óh  — t         j                  | j                  || j                  j                  | j                  j
                  | j                  j                  «      }t        j                  }|sZt         j                  | j                  || j                  j                  | j                  j                  «      }t        j                  }|sdt        j                  fS t         j                  || j                  j                  | j                  | j                   «      st#        dt$        «       ||fS )Nr)   zignore '/Perms' verify failed)r‡   r‚   rˆ   rë   rÛ   rÝ   rÜ   rË   rÎ   r}   rÞ   rÍ   rÌ   r³   rß   rQ   ræ   r   rC   )r&   rM   r;   r  s       r'   r  zEncryption.verify_v5å  s×   € ô ×)Ñ)Ø�F‰F�H˜dŸk™kŸm™m¨T¯[©[¯^©^¸T¿[¹[¿]¹]ó
ˆô ×(Ñ(ˆÙÜ×,Ñ,Ø—‘˜ $§+¡+§-¡-°·±·±óˆCô ×+Ñ+ˆBÙØœ×2Ñ2Ð2Ð2ô ×!Ñ! # t§{¡{×'8Ñ'8¸$¿&¹&À$×BVÑBVÔWÜÐ:¼HÔEØ�Bˆwˆr)   rk   rf   c                 óà  — | j                  |«      }|r| j                  |«      nd }|€|}| j                  dk  r| j                  ||«       nÍt        j                  | j
                  dz  «      | _        t        j                  | j                  ||| j                  | j                  | j                  «      }|d   | j                  _        |d   | j                  _        |d   | j                  _        |d   | j                  _        |d   | j                  _        t%        «       }t'        | j                  «      |t)        d«      <   t'        | j                  «      |t)        d	«      <   t'        | j
                  «      |t)        d
«      <   t'        | j                  «      |t)        d«      <   t)        d«      |t)        d«      <   t+        | j                  j                  «      |t)        d«      <   t+        | j                  j                  «      |t)        d«      <   | j                  dk\  rºt%        «       }t)        d«      |t)        d«      <   t)        | j,                  «      |t)        d«      <   t'        | j
                  dz  «      |t)        d
«      <   t%        «       }||t)        d«      <   ||t)        d«      <   t)        d«      |t)        d«      <   t)        d«      |t)        d«      <   | j                  dk\  r�t+        | j                  j                  «      |t)        d«      <   t+        | j                  j                   «      |t)        d«      <   t+        | j                  j"                  «      |t)        d«      <   |S )NrV   rX   r·   rµ   r¸   r¶   r¹   ú/Vú/Rú/Lengthú/Pú	/Standardú/Filterz/DocOpenz
/AuthEventú/CFMz/StdCFú/CFú/StmFú/StrFrÒ   )r  rã   Úcompute_values_v4r¿   rÀ   rä   rî   r‡   r»   rˆ   rQ   ræ   rë   rÛ   rÜ   rÝ   rÞ   rß   r   r   r   r   rè   )	r&   rk   rf   Úuser_pwdÚ	owner_pwdrë   Údict_objÚstd_cfr÷   s	            r'   Úwrite_entryzEncryption.write_entryù  s°  € ð ×(Ñ(¨Ó7ˆÙ=K�D×)Ñ)¨.Ô9ÐQUˆ	ØÐØ ˆIà�6‰6�QŠ;Ø×"Ñ" 8¨YÕ7ä×+Ñ+¨D¯K©K¸1Ñ,<Ó=ˆDŒIÜ×*Ñ*Ø—‘˜ )¨T¯Y©Y¸¿¹À×@TÑ@TóˆFð # 4™LˆD�K‰KŒMØ" 4™LˆD�K‰KŒMØ# E™]ˆD�K‰KŒNØ# E™]ˆD�K‰KŒNØ & xÑ 0ˆD�K‰KÔä#Ó%ˆÜ%1°$·&±&Ó%9ˆ”˜DÓ!Ñ"Ü%1°$·&±&Ó%9ˆ”˜DÓ!Ñ"Ü*6°t·{±{Ó*Cˆ”˜IÓ&Ñ'Ü%1°$·&±&Ó%9ˆ”˜DÓ!Ñ"Ü*4°[Ó*Aˆ”˜IÓ&Ñ'ô &6°d·k±k·m±mÓ%Dˆ”˜DÓ!Ñ"Ü%5°d·k±k·m±mÓ%Dˆ”˜DÓ!Ñ"à�6‰6�QŠ;ä%Ó'ˆFÜ/9¸*Ó/EˆF”:˜lÓ+Ñ,Ü)3°D·I±IÓ)>ˆF”:˜fÓ%Ñ&Ü,8¸¿¹ÈÑ9IÓ,JˆF”:˜iÓ(Ñ)Ü!Ó#ˆBØ'-ˆBŒz˜(Ó#Ñ$Ø*,ˆH”Z Ó&Ñ'Ü,6°xÓ,@ˆH”Z Ó(Ñ)Ü,6°xÓ,@ˆH”Z Ó(Ñ)ð �6‰6�QŠ;Ü*:¸4¿;¹;¿>¹>Ó*JˆH”Z Ó&Ñ'Ü*:¸4¿;¹;¿>¹>Ó*JˆH”Z Ó&Ñ'Ü-=¸d¿k¹k×>OÑ>OÓ-PˆH”Z Ó)Ñ*Øˆr)   c           	      óÞ  — t         j                  || j                  | j                  «      }t         j	                  ||| j                  «      }t         j                  || j                  | j                  || j                  | j                  | j                  «      }t         j                  || j                  | j                  «      }|| _
        || j                  _        || j                  _        y r%   )rL   ri   rˆ   rä   rt   re   rQ   rR   ræ   rx   rî   rë   rÛ   rÜ   )r&   rk   rf   rj   r‰   r;   r|   s          r'   r"  zEncryption.compute_values_v4-  s¬   € Ü×+Ñ+¨N¸D¿F¹FÀDÇKÁKÓPˆÜ×'Ñ'¨°ÀÇÁÓGˆä×ÑØØ�F‰FØ�K‰KØØ�F‰FØ�N‰NØ× Ñ ó
ˆô ×'Ñ'¨¨T¯V©V°T·^±^ÓDˆàˆŒ	Øˆ�‰ŒØˆ�‰�r)   Úencryption_entryc                 óh  — | j                  d«      dk7  rt        d«      ‚d| v rt        d«      ‚d}d}d}| j                  dd«      }|d	vrt        d
|› d�«      ‚|dk\  r�| d   }| j                  dd«      }| j                  dd«      }| j                  d|«      }|dk7  r||   d   }|dk7  r||   d   }|dk7  r||   d   }d}||vrt        d|› d�«      ‚||vrt        d|› d�«      ‚||vrt        d|› d�«      ‚t        t        | d   «      }t        t        | d   «      }	| j                  dd«      }
| j                  d«      }|�|j                  nd}t        «       }t        t        | d   «      j                  |_        t        t        | d   «      j                  |_	        | j                  d t        «       «      j                  |_
        | j                  d!t        «       «      j                  |_        | j                  d"t        «       «      j                  |_        t        |||
|	||||||| ¬#«      S )$Nr  r  z1only Standard PDF encryption handler is availablez
/SubFilterz/SubFilter NOT supportedú/V2r  r   )r   rv   rY   rV   rÒ   zEncryption V=z NOT supportedrV   r  r   r	  r!  z/EFFr  )r	  r+  r  r  zStmF Method z NOT supported!zStrF Method zEFF Method r  r  r  r�   z/EncryptMetadataTr·   rµ   r¸   r¶   r¹   ©rã   rˆ   rä   rQ   ræ   rç   rë   ré   rè   rê   rå   )ÚgetÚNotImplementedErrorr   r„   r<   rÚ   r   r3   rÛ   rÜ   rÝ   rÞ   rß   râ   )r)  rç   Ú
stm_filterÚ
str_filterÚ	ef_filterÚalg_verÚfiltersÚallowed_methodsÚalg_revÚ
perm_flagsÚkey_bitsÚencrypt_metadatarë   s                r'   ÚreadzEncryption.read@  s„  € à×Ñ 	Ó*¨kÒ9Ü%ØCóð ð Ð+Ñ+Ü%Ð&@ÓAÐAàˆ
Øˆ
Øˆ	à"×&Ñ& t¨QÓ/ˆØ˜/Ñ)Ü%¨°g°Y¸nÐ&MÓNÐNØ�aŠ<Ø& uÑ-ˆGà)×-Ñ-¨g°{ÓCˆJØ)×-Ñ-¨g°{ÓCˆJØ(×,Ñ,¨V°ZÓ@ˆIà˜[Ò(Ø$ ZÑ0°Ñ8�
Ø˜[Ò(Ø$ ZÑ0°Ñ8�
Ø˜KÒ'Ø# IÑ.¨vÑ6�	àFˆOØ Ñ0Ü)¨L¸¸ÀOÐ*TÓUÐUØ Ñ0Ü)¨L¸¸ÀOÐ*TÓUÐUØ Ñ/Ü)¨K¸	°{À/Ð*RÓSÐSä”sÐ,¨TÑ2Ó3ˆÜœ#Ð/°Ñ5Ó6ˆ
Ø#×'Ñ'¨	°2Ó6ˆØ+×/Ñ/Ð0BÓCÐà&6Ð&BÐ×"Ò"Èð 	ô "Ó#ˆÜÔ(Ð*:¸4Ñ*@ÓA×PÑPˆŒÜÔ(Ð*:¸4Ñ*@ÓA×PÑPˆŒØ$×(Ñ(¨Ô0@Ó0BÓC×RÑRˆŒ	Ø$×(Ñ(¨Ô0@Ó0BÓC×RÑRˆŒ	Ø'×+Ñ+¨HÔ6FÓ6HÓI×XÑXˆŒÜØØØØØ,Ø)ØØØØØ"ô
ð 	
r)   ÚalgÚpermissionsc                 óÚ   — | \  }}}d\  }}}| t         j                  k(  rd\  }}}n(| t         j                  t         j                  fv rd\  }}}t	        ||||d|d |||t        «       ¬«      S )N)r+  r+  r+  )r  r  r  )r  r  r  Tr,  )rÐ   rÖ   r×   rØ   râ   r   )	r:  r;  rç   r2  r5  r7  r/  r0  r1  s	            r'   ÚmakezEncryption.make�  s�   € ð &)Ñ"ˆ�˜(à,?Ñ)ˆ
�J 	àÔ"×*Ñ*Ò*Ø0LÑ-ˆJ˜
¡IØÔ%×0Ñ0Ô2B×2JÑ2JÐKÑKØ0LÑ-ˆJ˜
 IäØØØØØ Ø)ØØØØÜ"Ó$ô
ð 	
r)   )"rC   rD   rE   Ú__doc__r„   r   r…   rr   r  r   rÚ   r(   rð   r   r-   r?   rƒ   rô   r   rõ   r
   rý   r   r  rË   r  rÉ   r  r  r'  r"  r9  rÐ   r=  rF   r)   r'   râ   râ     sn  „ ñð0*àð*ð ð*ð ð	*ð
 ð*ð  ð*ð ð*ð ð*ð ð*ð ð*ð ð*ð Ð)Ñ*ð*ð 
ó*ð<A˜dó Að& )ð &°Cð &ÀSð &ÈYó &ð& )ð &°Cð &ÀSð &ÈYó &ð ð

 9ð 

°ò 

ó ð

ð=;¨ð =;¸ð =;Àó =;ð~ ð
!Øð
!Ø#ð
!Ø16ð
!ØDIð
!à	ò
!ó ð
!ð ð 5¨°¨Ñ#4ð ¸ò ó ðð˜u U¨C ZÑ0ð °\ó ð/ %ð /¨E°%¸Ð2EÑ,Fó /ð8 %ð ¨E°%¸Ð2EÑ,Fó ð(2Ø ð2Ø2:¸3±-ð2à	ó2ðh ¨uð  Àeð  ÐPTó  ð& ð>
Ð/ð >
Àð >
È<ò >
ó ð>
ð@ ð
Øð
Ø,/ð
ØAFð
à	ò
ó ñ
r)   râ   )-r[   r¿   r]   Úenumr   r   Útypingr   r   r   r   Úpypdf._crypt_providersr	   r
   r   r   r   r   r   r   r   r   Ú_utilsr   Úgenericr   r   r   r   r   r   r   r   r   r   rI   rr   rJ   rL   r‡   rË   rÉ   rÐ   rÚ   râ   rF   r)   r'   Ú<module>rD     s¯   ðó6 Û Û ß ß -Ó -÷÷ ÷ õ #÷
÷ 
õ 
÷0ñ 0ðhHð 	ð"�5ð "˜Uó "÷\
ñ \
÷~
a*ñ a*ôH	�7ô ô�u˜dô ÷ñ ÷G
ò G
r)   