
     hI                     R   d dl 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 d dlmZ d dlmZ d d	lmZ d
dgZ ej        dd           ej        de           ej        d ej        dd                     ej        ddde           ej        dddd ej        dd                    d                                                             Z ej        dd
          d             Z ej        dd dedd!          Ze                    d"d#           ej        de           ej        d ej        dd                     ej        dd$de          ed%                                                             Ze                    d&d'           ej        de           ej        d ej        dd                     ej        d(edd)*           ej        d+d,ed-           ej        d.d ej        d/          d0d12           ej        d3d4eddd5          ed6                                                                                                 Z d7ej!        fd8Z"e                    d9d:           ej        de           ej        d ej        dd                     ej        d;e           ej        d.d ej        d<          d=d12          ed>                                                                         Z#dS )?    N)cli_root)pyhanko_exception_manager)_warn_empty_passphrasereadable_file)load_certs_from_pemder)crypt)StandardSecurityHandler)PdfFileReader)copy_into_new_writerdecryptencrypt_filez encrypt PDF files (AES-256 only)encrypt)helpnameinfile)typeoutfileTF)writabledir_okayz
--passwordz!password to encrypt the file with)r   requiredr   z--recipientzIcertificate(s) corresponding to entities that can decrypt the output file)readabler   )r   multipler   r   c                 Z   |r|rt          j        d          |s|st          j        d          }d }|rt          t	          |                    }t                      5  t          | d          5 }t          |          }t          |          }|r|	                    |           n|
                    |           t          |d          5 }|                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz2Specify either a password or a list of recipients.zOutput file password: prompt)
cert_filesrb)
owner_passwb)clickClickExceptiongetpasslistr   r   openr
   r   encrypt_pubkeyr   write)	r   r   password	recipientrecipient_certsinfrwoutfs	            V/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/cli/commands/crypt.pyr   r      s
   $  DI D"@
 
 	
  Di D?*BCCCO M5KKKLL	"	$	$  &$ 
	3c""A$Q''A /  1111		X	...gt$$               
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	                 s[   !D 2ADC1%D1C55D8C59D<D D	D D	D  D$'D$z6decrypt PDF files (any standard PDF encryption scheme)c                      d S )N r0       r.   r   r   <   s	    
 	Dr1   z--forcez1ignore access restrictions (use at your own risk))r   r   r   is_flagdefaultzdecrypt using passwordr'   z!password to decrypt the file withc                     t                      5  t          | d          5 }t          |          }|j        t	          j        d          t          |j        t                    st	          j        d          |st          j        d          }|	                    |          }|j
        t          j        j        k    r|st	          j        d          |j
        t          j        j        k    rt	          j        d          t          |          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	Nr   File is not encrypted.zIFile is not encrypted with the standard (password-based) security handlerzFile password: r   zjPassword specified was the user password, not the owner password. Pass --force to decrypt the file anyway.zPassword didn't match.r   )r   r$   r
   security_handlerr    r!   
isinstancer	   r"   r   statusr   
AuthStatusUSERFAILEDr   r&   )	r   r   r'   forcer*   r+   auth_resultr,   r-   s	            r.   decrypt_with_passwordr>   N   s4    
#	$	$  &$ 	3c""A!)*+CDDD 24KLL *_    E"?2CDDD))H--K!U%5%:::5:*#  
 #u'7'>>>*+CDDD$Q''Agt$$               )	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 sY   E3DE"E8EEEEEE3E	E3"E	#E33E7:E7z#decrypt using private key (PEM/DER)pemderz--keyz5file containing the recipient's private key (PEM/DER))r   r   r   z--certz5file containing the recipient's certificate (PEM/DER))r   r   r   z
--passfiler   z2file containing the passphrase for the private keystdin)r   r   r   show_defaultz	--no-passz*assume the private key file is unencrypted)r   r   r2   r3   rA   c                 B   |)|                                 }|                                 n?|s;t          j        d                              d          }|st	                       d }nd }t
          j                            |||          }t          || ||           d S )NKey passphrase: r   utf-8)key_passphrase)	readcloser"   encoder   r   SimpleEnvelopeKeyDecrypterload_decrypt_pubkey)	r   r   keycertpassfiler<   no_pass
passphrasesedks	            r.   decrypt_with_pemderrR   r   s    @ ]]__
 _,>???FFwOO
 	"$$$J
+00T* 1  D D&'511111r1   rQ   c                    t                      5  t          |d          5 }t          |          }|j        t	          j        d          t          |j        t          j                  st	          j        d          |	                    |           }|j
        t          j        j        k    r|st	          j        d          n.|j
        t          j        j        k    rt	          j        d          t          |          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r5   z:File was not encrypted with a public-key security handler.zhChange of encryption is typically not allowed with user access. Pass --force to decrypt the file anyway.zFailed to decrypt the file.r   )r   r$   r
   r6   r    r!   r7   r   PubKeySecurityHandlerdecrypt_pubkeyr8   r9   r:   r;   r   r&   )	rQ   r   r   r<   r*   r+   r=   r,   r-   s	            r.   rK   rK      s'    
#	$	$  &$ 	3c""A!)*+CDDDa0%2MNN *P   **400K!U%5%:::  .P  
 #u'7'>>>*+HIII$Q''Agt$$               )	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 sY   E"C1E
D3'E
3D77E
:D7;E
>E"
E	E"E	E""E&)E&z#decrypt using private key (PKCS#12)pkcs12pfxr+   z3file containing the passphrase for the PKCS#12 filec                 \   |)t          j         d                              d          }nM|                                                                                    d          }|                                 t
          j                            ||          }t          || ||           d S )NrC   r   rD   )rP   )	r"   rH   readlinestriprG   r   rI   load_pkcs12rK   )r   r   rW   rN   r<   rP   rQ   s          r.   decrypt_with_pkcs12r\      s     _,>???FFwOO

&&((..0077@@
+77
 8  D D&'511111r1   )$r"   r    pyhanko.cli._rootr   pyhanko.cli.runtimer   pyhanko.cli.utilsr   r   pyhanko.keysr   pyhanko.pdf_utilsr   pyhanko.pdf_utils.cryptr	   pyhanko.pdf_utils.readerr
   pyhanko.pdf_utils.writerr   __all__commandargumentPathoptionstrr   groupr   booldecrypt_force_flagr>   FilerR   rI   rK   r\   r0   r1   r.   <module>ro      s	     & & & & & & 9 9 9 9 9 9 C C C C C C C C / / / / / / # # # # # # ; ; ; ; ; ; 2 2 2 2 2 2 9 9 9 9 9 9n
% 9	JJJ}---	

D5 I I IJJJ	,		   
"	TE	2	2	2      KJ .- KJ"4 	A	  	 		 	 "U\	<	    	.Z@@}---	

D5 I I IJJJ	,		       KJ .- A@4 	;(KK}---	

D5 I I IJJJ		A	   	A		   	D			=   	5	   2 2      KJ .- LK>2&

*   8 	;(KK}---	

D5 I I IJJJM***	C	>   
2 
2   +* KJ .- LK
2 
2 
2r1   