
    &g'                        d Z ddlZddlZddlZddlZddlZddlZddlZ eej	        j
                                                  Z
ej        ej        ej        e         f         ZddZ G d dej                  Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z e            Z e            Z e            Z e            ZdS )zWCommandline scripts.

These scripts are called by the executables defined in setup.py.
    Nreturnc                  r   t          j        dd          } |                     ddd           |                     dd	dd
           |                     dddd           |                     t          j        dd                   \  }}t          |          dk    r#|                                  t          d          	 t          |d                   }nZ# t          $ rM}|                                  t          d|d         z  t          j                   t          d          |d}~ww xY wt          d|z  t          j                   t          j        |          \  }}|j        rt          d|j        z  t          j                   |                    |j                  }t%          |j        d          5 }|                    |           ddd           n# 1 swxY w Y   |                    |j                  }|j        rht          d|j        z  t          j                   t%          |j        d          5 }|                    |           ddd           dS # 1 swxY w Y   dS t          dt          j                   t          j        j                            |           dS )zKey generator.zusage: %prog [options] keysizez/Generates a new RSA key pair of "keysize" bits.usagedescriptionz--puboutstringzOutput filename for the public key. The public key is not saved if this option is not present. You can use pyrsa-priv2pub to create the public key file later.typehelp-oz--outz`Output filename for the private key. The key is written to stdout if this option is not present.z--formz7key format of the private and public keys - default PEMPEMDERr   r   choicesdefault   Nr   zNot a valid number: %sfilezGenerating %i-bit keyzWriting public key to %s)formatwbzWriting private key to %szWriting private key to stdout)optparseOptionParser
add_option
parse_argssysargvlen
print_help
SystemExitint
ValueErrorprintstderrrsanewkeyspubout
save_pkcs1formopenwriteoutstdoutbuffer)	parserclicli_argskeysizeexpub_keypriv_keydataoutfiles	            9/var/www/api/venv/lib/python3.11/site-packages/rsa/cli.pykeygenr9   !   sP    ".E  F
 >     ;	     F	     ''55OS(
8}}mm$hqk"" $ $ $&!43:FFFFmm#$
 

!G
+#*====+g..Wh z  (3:5CJGGGG!!!22#*d## 	 wMM$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  ch//D
w &)CG3#*EEEE#'4   	 GMM$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	-CJ????
%%%%%s=   C 
D/"AD**D/G##G'*G'I++I/2I/c            	       :   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ej        ZddZej        dedej        j        dedej        fd            ZddZdej        ej        ej        e          f         fdZ!de de dej        j        fdZ"de defdZ#dede ddfdZ$dS )CryptoOperationz9CLI callable that operates with input, output, and a key.publicz'usage: %%prog [options] %(keyname)s_key decrypt	decrypted
decryptingzEName of the file to %(operation)s. Reads from stdin if not specified.zjName of the file to write the %(operation_past)s file to. Written to stdout if this option is not present.r   Tr   Nc                     | j         | j        j        z  | _         | j        | j        j        z  | _        | j        | j        j        z  | _        d S )N)r   	__class____dict__
input_helpoutput_help)selfs    r8   __init__zCryptoOperation.__init__w   sC    Z$."99
/DN,CC+dn.EE    indatakeyr1   c                     dS )zPerforms the program's operation.

        Implement in a subclass.

        :returns: the data to write to the output.
        N )rF   rI   rJ   r1   s       r8   perform_operationz!CryptoOperation.perform_operation|   s      rH   c                    |                                  \  }}|                     |d         |j                  }|                     |j                  }t          | j                                        t          j	                   | 
                    |||          }| j        r|                     ||j                   dS dS )zRuns the program.r   r   N)	parse_cliread_keykeyformread_infileinputr#   operation_progressivetitler   r$   rM   
has_outputwrite_outfileoutput)rF   r0   r1   rJ   rI   outdatas         r8   __call__zCryptoOperation.__call__   s     ..**hmmHQK55!!#),,d(..00szBBBB((h??? 	4w
33333	4 	4rH   c                    t          j        | j        | j                  }|                    ddd| j                   | j        r|                    ddd| j                   |                    dd	| j        z  d
d           |	                    t          j        dd                   \  }}t          |          | j        k    r#|                                 t          d          ||fS )zFParse the CLI options

        :returns: (cli_opts, cli_args)
        r   z-iz--inputr   r	   r   z--outputz	--keyformz&Key format of the %s key - default PEMr   r   r   r   N)r   r   r   r   r   rD   rV   rE   keynamer   r   r   r   expected_cli_argsr   r    )rF   r/   r0   r1   s       r8   rO   zCryptoOperation.parse_cli   s     &TZTEUVVV$	tOOO? 	VdJXDDTUUU9DLH"	 	 	
 	
 	
 !++CHQRRL99hx==D222Q--H}rH   filenamerQ   c                     t          d| j        d|t          j                   t	          |d          5 }|                                }ddd           n# 1 swxY w Y   | j                            ||          S )zReads a public or private key.zReading z
 key from r   rbN)r#   r\   r   r$   r*   read	key_class
load_pkcs1)rF   r^   rQ   keyfilekeydatas        r8   rP   zCryptoOperation.read_key   s     	$,,,A
SSSS(D!! 	%WllnnG	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ~((':::s   AAAinnamec                 6   |rZt          d|z  t          j                   t          |d          5 }|                                cddd           S # 1 swxY w Y   t          dt          j                   t          j        j                                        S )zRead the input filezReading input from %sr   r`   NzReading input from stdin)r#   r   r$   r*   ra   stdinr.   )rF   rf   infiles      r8   rR   zCryptoOperation.read_infile   s      	%)F2DDDDfd## %v{{}}% % % % % % % % % % % % % % % % 	(sz::::y$$&&&s   AAArY   outnamec                 D   |r^t          d|z  t          j                   t          |d          5 }|                    |           ddd           dS # 1 swxY w Y   dS t          dt          j                   t          j        j                            |           dS )zWrite the output filezWriting output to %sr   r   NzWriting output to stdout)r#   r   r$   r*   r+   r-   r.   )rF   rY   rj   r7   s       r8   rW   zCryptoOperation.write_outfile   s      	-(72DDDDgt$$ 'g&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ,3:>>>>J##G,,,,,s   AAAr   N)%__name__
__module____qualname____doc__r\   r   r   	operationoperation_pastrT   rD   rE   r]   rV   r%   	PublicKeyrb   rG   abcabstractmethodbytesrJ   AbstractKey	IndexabletypingAnyrM   rZ   Tupler   ValuesListstrrO   rP   rR   rW   rL   rH   r8   r;   r;   d   s|       CCG5EKI N([J	?  JIF F F F
 	"%'"5AJ	   4 4 4 46<S9I(IJ    8; ;s ;sw7J ; ; ; ;	'# 	'% 	' 	' 	' 	'	-U 	-S 	-T 	- 	- 	- 	- 	- 	-rH   r;   )	metaclassc            	       V    e Zd ZdZdZdZdZdZdZ	 dde	d	e
j        j        d
ede	fdZdS )EncryptOperationzEncrypts a file.r<   zWEncrypts a file. The file must be shorter than the key length in order to be encrypted.encrypt	encrypted
encryptingrL   rI   r4   r1   r   c                 n    t          |t          j        j                  sJ t          j        ||          S )zEncrypts files.)
isinstancer%   rJ   rs   r   )rF   rI   r4   r1   s       r8   rM   z"EncryptOperation.perform_operation   s1     '37#455555{67+++rH   NrL   )rm   rn   ro   rp   r\   r   rq   rr   rT   rv   r%   rJ   rw   rx   rM   rL   rH   r8   r   r      s~        Gd  I N( RT, ,,&)g&9,EN,	, , , , , ,rH   r   c            	       d    e Zd ZdZdZdZdZdZdZe	j
        Z	 dded	e	j        j        d
edefdZdS )DecryptOperationzDecrypts a file.privatezgDecrypts a file. The original file must be shorter than the key length in order to have been encrypted.r>   r?   r@   rL   rI   r5   r1   r   c                 n    t          |t          j        j                  sJ t          j        ||          S )zDecrypts files.)r   r%   rJ   
PrivateKeyr>   )rF   rI   r5   r1   s       r8   rM   z"DecryptOperation.perform_operation   s1     (CG$677777{68,,,rH   Nr   )rm   rn   ro   rp   r\   r   rq   rr   rT   r%   r   rb   rv   rJ   rw   rx   rM   rL   rH   r8   r   r      s        G	:  I N(I SU- --'*w':-FO-	- - - - - -rH   r   c                       e Zd ZdZdZdZdd                    e          z  ZdZ	dZ
dZej        Zd	Zd
Zdedej        j        dedefdZdS )SignOperationzSigns a file.r   z/usage: %%prog [options] private_key hash_methodzCSigns a file, outputs the signature. Choose the hash method from %s, sign	signatureSigning   z\Name of the file to write the signature to. Written to stdout if this option is not present.rI   r5   r1   r   c                     t          |t          j        j                  sJ |d         }|t          vr*t          dd                    t                    z            t          j        |||          S )zSigns files.r   z%Invalid hash method, choose one of %sr   )r   r%   rJ   r   HASH_METHODSr    joinr   )rF   rI   r5   r1   hash_methods        r8   rM   zSignOperation.perform_operation  sh     (CG$677777qkl**DtyyQ]G^G^^___x+666rH   N)rm   rn   ro   rp   r\   r   r   r   r   rq   rr   rT   r%   r   rb   r]   rE   rv   rJ   rw   rx   rM   rL   rH   r8   r   r      s        G=E	99\22	3  I N%I	3 

7
7'*w':
7FO
7	
7 
7 
7 
7 
7 
7rH   r   c                   l    e Zd ZdZdZdZdZdZdZdZ	e
j        ZdZd	Zd
ede
j        j        deddfdZdS )VerifyOperationzVerify a signature.r<   z1usage: %%prog [options] public_key signature_filezsVerifies a signature, exits with status 0 upon success, prints an error message and exits with status 1 upon error.verifyverified	Verifyingr   FrI   r4   r1   r   Nc                    t          |t          j        j                  sJ |d         }t	          |d          5 }|                                }ddd           n# 1 swxY w Y   	 t          j        |||           n'# t          j        $ r}t          d          |d}~ww xY wt          dt          j                   dS )zVerifies files.r   r`   NzVerification failed.zVerification OKr   )r   r%   rJ   rs   r*   ra   r   VerificationErrorr    r#   r   r$   )rF   rI   r4   r1   signature_filesigfiler   r3   s           r8   rM   z!VerifyOperation.perform_operation+  s    '37#455555!!.$'' 	'7I	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'	=Jvy'2222$ 	= 	= 	=344"<	= 	cj111111s)   AA"A'A> >B"BB")rm   rn   ro   rp   r\   r   r   rq   rr   rT   r%   rs   rb   r]   rV   rv   rJ   rw   rx   rM   rL   rH   r8   r   r     s        G?E	F  IN'IJ22&)g&92EN2	2 2 2 2 2 2rH   r   rl   )rp   rt   r   ry   r   r%   rsa.key	rsa.pkcs1sortedpkcs1r   keysUnionr{   r}   r~   rx   r9   ABCMetar;   r   r   r   r   r   r>   r   r   rL   rH   r8   <module>r      s   
 


 



   



     vci,113344Lv{3'778	@& @& @& @&Fk- k- k- k- k- k- k- k- k-\, , , , , , , ,&- - - - - - - -*7 7 7 7 7O 7 7 7B 2  2  2  2  2o  2  2  2F 






}			rH   