
    (ph&                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKr\" \R                  R                  R                  5       5      r
\R                  \R                  \R                  \   4   rSS jr " S S\R$                  S9r " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r\" 5       r\" 5       r\" 5       r\" 5       rg)zWCommandline scripts.

These scripts are called by the executables defined in setup.py.
    Nc                     [         R                  " SSS9n U R                  SSSS9  U R                  SS	SS
S9  U R                  SSSSS9  U R                  [        R
                  SS 5      u  p[        U5      S:w  a  U R                  5         [        S5      e [        US   5      n[        SU-  [        R                  S9  [        R                  " U5      u  pVUR                  (       an  [        SUR                  -  [        R                  S9  UR!                  UR"                  S9n[%        UR                  S5       nUR'                  U5        SSS5        UR!                  UR"                  S9nUR(                  (       aV  [        SUR(                  -  [        R                  S9  [%        UR(                  S5       nUR'                  U5        SSS5        g[        S[        R                  S9  [        R*                  R,                  R'                  U5        g! [         a?  nU R                  5         [        SUS   -  [        R                  S9  [        S5      UeSnAff = f! , (       d  f       GN= f! , (       d  f       g= f)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	            :/var/www/html/venv/lib/python3.13/site-packages/rsa/cli.pykeygenr8   !   s*    "".EF
 >   ;	   F	   ''5OS
8}m$hqk" 

!G
+#**=++g.W zz(3::5CJJG!!!2#**d#wMM$ $ chh/D
ww)CGG3#**E#''4 GMM$ !  	-CJJ?

%1  $&!43::Fm#$ $# ! s0   H  I(?I:
I%&:I  I%(
I7:
Jc            	          \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSr\R                   rSS jr\R(                  S\S\R,                  R.                  S\S\R4                  4S j5       rSS jrS\R:                  \R>                  \R@                  \!   4   4S jr"S\!S\!S\R,                  R.                  4S jr#S\!S\4S jr$S\S\!SS4S jr%Sr&g) CryptoOperationd   z9CLI 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   TreturnNc                     U R                   U R                  R                  -  U l         U R                  U R                  R                  -  U l        U R                  U R                  R                  -  U l        g )N)r   	__class____dict__
input_helpoutput_help)selfs    r7   __init__CryptoOperation.__init__w   sS    ZZ$.."9"99
//DNN,C,CC++dnn.E.EE    indatakeyr0   c                     g)zhPerforms the program's operation.

Implement in a subclass.

:returns: the data to write to the output.
N )rG   rK   rL   r0   s       r7   perform_operation!CryptoOperation.perform_operation|   s    rJ   c                 z   U R                  5       u  pU R                  US   UR                  5      nU R                  UR                  5      n[        U R                  R                  5       [        R                  S9  U R                  XCU5      nU R                  (       a  U R                  XQR                  5        gg)zRuns the program.r   r   N)	parse_cliread_keykeyformread_infileinputr"   operation_progressivetitler   r#   rO   
has_outputwrite_outfileoutput)rG   r/   r0   rL   rK   outdatas         r7   __call__CryptoOperation.__call__   s     ..*mmHQK5!!#)),d((..0szzB((h???w

3 rJ   c                    [         R                  " U R                  U R                  S9nUR	                  SSSU R
                  S9  U R                  (       a  UR	                  SSSU R                  S9  UR	                  SS	U R                  -  S
SS9  UR                  [        R                  SS 5      u  p#[        U5      U R                  :w  a  UR                  5         [        S5      eX#4$ )z6Parse 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   rE   rY   rF   keynamer   r   r   r   expected_cli_argsr   r   )rG   r.   r/   r0   s       r7   rR   CryptoOperation.parse_cli   s     &&TZZTEUEUV$	tO??dJXDDTDTU9DLLH"	 	 	
 !++CHHQRL9x=D222Q-}rJ   filenamerT   c                     [        SU R                  < SU< 3[        R                  S9  [	        US5       nUR                  5       nSSS5        U R                  R                  WU5      $ ! , (       d  f       N*= f)zReads a public or private key.zReading z
 key from r   rbN)r"   r`   r   r#   r)   read	key_class
load_pkcs1)rG   rc   rT   keyfilekeydatas        r7   rS   CryptoOperation.read_key   sY     	$,,A

S(D!WllnG " ~~((':: "!s   A,,
A:innamec                 4   U(       aA  [        SU-  [        R                  S9  [        US5       nUR	                  5       sSSS5        $ [        S[        R                  S9  [        R
                  R                  R	                  5       $ ! , (       d  f       NN= f)zRead the input filezReading input from %sr   re   NzReading input from stdin)r"   r   r#   r)   rf   stdinr-   )rG   rl   infiles      r7   rU   CryptoOperation.read_infile   sk     )F2Dfd#v{{} $# 	(szz:yy$$&&	 $#s   B		
Br\   outnamec                 :   U(       aB  [        SU-  [        R                  S9  [        US5       nUR	                  U5        SSS5        g[        S[        R                  S9  [        R
                  R                  R	                  U5        g! , (       d  f       g= f)zWrite the output filezWriting output to %sr   r   NzWriting output to stdout)r"   r   r#   r)   r*   r,   r-   )rG   r\   rq   r6   s       r7   rZ   CryptoOperation.write_outfile   sm     (72Dgt$g& %$ ,3::>JJ##G,	 %$s   B
B)rE   rF   r   rA   N)'__name__
__module____qualname____firstlineno____doc__r`   r   r   	operationoperation_pastrW   rE   rF   ra   rY   r$   	PublicKeyrg   rH   abcabstractmethodbytesrL   AbstractKey	IndexabletypingAnyrO   r]   Tupler   ValuesListstrrR   rS   rU   rZ   __static_attributes__rN   rJ   r7   r:   r:   d   s   CG5EKI N([J	?  JIF
 	"%''"5"5AJ	 46<<S9I(IJ 8; ;s ;sww7J7J ;	'# 	'% 	'	-U 	-S 	-T 	-rJ   r:   )	metaclassc            	       t    \ rS rSrSrSrSrSrSrSr	 SS	\
S
\R                  R                  S\S\
4S jjrSrg)EncryptOperation   zEncrypts a file.r<   zWEncrypts a file. The file must be shorter than the key length in order to be encrypted.encrypt	encrypted
encryptingrN   rK   r3   r0   rA   c                     [        U[        R                  R                  5      (       d   e[        R                  " X5      $ )zEncrypts files.)
isinstancer$   rL   r|   r   )rG   rK   r3   r0   s       r7   rO   "EncryptOperation.perform_operation   s0     '377#4#45555{{6++rJ   NrN   )ru   rv   rw   rx   ry   r`   r   rz   r{   rW   r   r$   rL   r   r   rO   r   rN   rJ   r7   r   r      s_    Gd  I N( RT,,&)gg&9&9,EN,	, ,rJ   r   c            	           \ rS rSrSrSrSrSrSrSr	\
R                  r SS	\S
\
R                  R                  S\S\4S jjrSrg)DecryptOperation   z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@   rN   rK   r4   r0   rA   c                     [        U[        R                  R                  5      (       d   e[        R                  " X5      $ )zDecrypts files.)r   r$   rL   
PrivateKeyr>   )rG   rK   r4   r0   s       r7   rO   "DecryptOperation.perform_operation   s0     (CGG$6$67777{{6,,rJ   Nr   )ru   rv   rw   rx   ry   r`   r   rz   r{   rW   r$   r   rg   r   rL   r   r   rO   r   rN   rJ   r7   r   r      sj    G	:  I N(I SU--'*ww':':-FO-	- -rJ   r   c                       \ rS rSrSrSrSrSSR                  \5      -  r	Sr
SrS	r\R                  rS
rSrS\S\R&                  R(                  S\S\4S jrSrg)SignOperation   z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.rK   r4   r0   rA   c                     [        U[        R                  R                  5      (       d   eUS   nU[        ;  a!  [        SSR                  [        5      -  5      e[        R                  " XU5      $ )zSigns files.r   z%Invalid hash method, choose one of %sr   )r   r$   rL   r   HASH_METHODSr   joinr   )rG   rK   r4   r0   hash_methods        r7   rO   SignOperation.perform_operation  s^     (CGG$6$67777qkl*DtyyQ]G^^__xx+66rJ   rN   N)ru   rv   rw   rx   ry   r`   r   r   r   r   rz   r{   rW   r$   r   rg   ra   rF   r   rL   r   r   rO   r   rN   rJ   r7   r   r      s    G=E	99\2	3  I N%I	3 

7
7'*ww':':
7FO
7	
7rJ   r   c                       \ rS rSrSrSrSrSrSrSr	Sr
\R                  rS	rS
rS\S\R"                  R$                  S\SS4S jrSrg)VerifyOperationi  z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   FrK   r3   r0   rA   Nc                    [        U[        R                  R                  5      (       d   eUS   n[	        US5       nUR                  5       nSSS5         [        R                  " UWU5        [        S[        R                  S9  g! , (       d  f       N@= f! [        R                   a  n[        S5      UeSnAff = f)zVerifies files.r   re   NzVerification failed.zVerification OKr   )r   r$   rL   r|   r)   rf   r   VerificationErrorr   r"   r   r#   )rG   rK   r3   r0   signature_filesigfiler   r2   s           r7   rO   !VerifyOperation.perform_operation+  s     '377#4#45555!!.$'7I (	=JJvy'2 	cjj1 ('
 $$ 	=34"<	=s#   BB 
BB>-B99B>rN   )ru   rv   rw   rx   ry   r`   r   r   rz   r{   rW   r$   r|   rg   ra   rY   r   rL   r   r   rO   r   rN   rJ   r7   r   r     so    G?E	F  IN'IJ22&)gg&9&92EN2	2rJ   r   rt   )ry   r}   r   r   r   r$   rsa.key	rsa.pkcs1sortedpkcs1r   keysUnionr   r   r   r   r8   ABCMetar:   r   r   r   r   r   r>   r   r   rN   rJ   r7   <module>r      s   
  
   
  cii,,1134LLv{{3'778	@&Fk- k-\, ,&- -*7O 7B 2o  2F 


		rJ   