
    Wwg]                     z    d dl Z d dlZd dlmZ d dlmZ g dZ G d de      Z G d dee      Z G d	 d
ee      Z	y)    N)Flag)reduce)PdfPermissionsStandardPermissionsPubKeyPermissionsc                       e Zd ZdZed        Zedefd       Zedefd       Z	edefd       Z
d	efd
Zd	efdZd	efdZd	efdZy)r   z1
    Utility mixin for PDF permission flags.
    c                 f    t        t        j                  | j                  j	                               S )z&
        Set all permissions.
        )r   operatoror___members__values)clss    Z/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/pdf_utils/crypt/permissions.pyallow_everythingzPdfPermissions.allow_everything   s"     hllCOO$:$:$<==    
uint_flagsc                 N     | d      }| D ]  }||j                   z  s||z  } |S )zN
        Convert a 32-bit unsigned integer into PDF permission flags.
        r   value)r   r   resultflags       r   	from_uintzPdfPermissions.from_uint   s8     Q 	DDJJ&$	 r   flagsc                 V    t        j                  d|      d   }| j                  |      S )zH
        Convert a string of 4 bytes into PDF permission flags.
        >Ir   )structunpackr   )r   r   r   s      r   
from_byteszPdfPermissions.from_bytes'   s(     ]]4/2
}}Z((r   sint32_flagsc                 *    | j                  |dz        S )zL
        Convert a 32-bit signed integer into PDF permission flags.
        l    )r   )r   r   s     r   from_sint32zPdfPermissions.from_sint320   s     }}\J677r   returnc                     t         )a  
        Convert a set of PDF permission flags to their 32-bit
        unsigned integer representation.

        This will already take into account some conventions
        in the PDF specification, i.e. to set as-yet undefined
        permission flags to 'Allow'.
        NotImplementedErrorselfs    r   	as_uint32zPdfPermissions.as_uint328   s
     "!r   c                 J    t        j                  d| j                               S )z_
        Convert a set of PDF permission flags to their binary
        representation.
        r   )r   packr(   r&   s    r   as_byteszPdfPermissions.as_bytesD   s    
 {{4!122r   c                 P    t        j                  d| j                               d   S )zg
        Convert a set of PDF permission flags to their
        signed integer representation.
        z>ir   )r   r   r+   r&   s    r   	as_sint32zPdfPermissions.as_sint32K   s     
 }}T4==?3A66r   c                     t         Nr$   r&   s    r   mac_requiredzPdfPermissions.mac_requiredR   s    !!r   N)__name__
__module____qualname____doc__classmethodr   intr   bytesr   r!   r(   r+   r-   boolr0    r   r   r   r   	   s     > > 	3 	 	 )u ) ) 8s 8 8
"3 
"3% 373 7"d "r   r   c                   L    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdefdZdefdZy)r   zd
    Permission flags for the standard security handler.

    See Table 22 in ISO 32000-2:2020.
                                r"   c                 F     t         fd j                  D              dz  S )Nc              3   @   K   | ]  }|v s|j                     y wr/   r   .0xr'   s     r   	<genexpr>z0StandardPermissions.as_uint32.<locals>.<genexpr>h        @qa4i177@   	l   ` sum	__class__r&   s   `r   r(   zStandardPermissions.as_uint32g   s    @DNN@@:MMr   c                 &    t         j                  | vS r/   )r   TOLERATE_MISSING_PDF_MACr&   s    r   r0   z StandardPermissions.mac_requiredj   s    ";;4GGr   N)r1   r2   r3   r4   ALLOW_PRINTINGALLOW_MODIFICATION_GENERICALLOW_CONTENT_EXTRACTIONALLOW_ANNOTS_FORM_FILLINGALLOW_FORM_FILLINGALLOW_ASSISTIVE_TECHNOLOGYALLOW_REASSEMBLYALLOW_HIGH_QUALITY_PRINTINGrP   r6   r(   r8   r0   r9   r   r   r   r   V   sZ     N!"! "!$"&#N3 NHd Hr   r   c                   P    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdefdZdefdZy)r   zf
    Permission flags for the public-key security handler.

    See Table 24 in ISO 32000-2:2020.
       r;   r<   r=   r>   r?   r@   rA   rB   rC   r"   c                 F     t         fd j                  D              dz  S )Nc              3   @   K   | ]  }|v s|j                     y wr/   r   rF   s     r   rI   z.PubKeyPermissions.as_uint32.<locals>.<genexpr>   rJ   rK   l   ` rL   r&   s   `r   r(   zPubKeyPermissions.as_uint32   s    @DNN@@:MMr   c                 &    t         j                  | vS r/   )r   rP   r&   s    r   r0   zPubKeyPermissions.mac_required   s     99EEr   N)r1   r2   r3   r4   ALLOW_ENCRYPTION_CHANGErQ   rR   rS   rT   rU   rV   rW   rX   rP   r6   r(   r8   r0   r9   r   r   r   r   n   s`      N!"! "!$"&#N3 NFd Fr   r   )
r
   r   enumr   	functoolsr   __all__r   r   r   r9   r   r   <module>rb      sE       
HJ"T J"ZH.$ H0F Fr   