;i&dZddlZddlZddlZddlZddlZddlZddlZeej j Z ej ej ejefZddZGddejZGdd eZGd d eZGd d eZGddeZeZeZeZeZdS)zWCommandline scripts. These scripts are called by the executables defined in setup.py. Nreturncrtjdd}|ddd|dd dd |d d d d|tjdd\}}t |dkr#|td t|d}nZ#t$rM}|td|dztj td|d}~wwxYwtd|ztj tj|\}}|jrtd|jztj ||j}t%|jd5}||dddn #1swxYwY||j}|jrhtd|jztj t%|jd5}||ddddS#1swxYwYdStdtj tjj|dS)zKey generator.zusage: %prog [options] keysizez/Generates a new RSA key pair of "keysize" bits.usage descriptionz--puboutstringzOutput 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.typehelp-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 PEMPEMDERrr choicesdefaultNrzNot a valid number: %sfilezGenerating %i-bit keyzWriting public key to %s)formatwbzWriting private key to %szWriting private key to stdout)optparse OptionParser add_option parse_argssysargvlen print_help SystemExitint ValueErrorprintstderrrsanewkeyspubout save_pkcs1formopenwriteoutstdoutbuffer) parserclicli_argskeysizeexpub_keypriv_keydataoutfiles ;C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\rsa/cli.pykeygenr9!sP ".EF   >   ;   F '' 55OS( 8}}mm$hqk"" $$$ &!43:FFFFmm#$  !G +#*====+g..Wh z  (3:5CJGGGG!!!22 #*d # # w MM$                     ch  / /D w& )CG3#*EEEE #'4  G MM$                      -CJ???? %%%%%s=C D/"AD**D/G##G'*G'I++I/2I/c :eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z ejZddZejdedejjded ejfdZddZd ejejeje ffdZ!de de d ejjfdZ"de d efdZ#dede d d fdZ$d S)CryptoOperationz9CLI callable that operates with input, output, and a key.publicz'usage: %%prog [options] %(keyname)s_keydecrypt 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.rTrNc|j|jjz|_|j|jjz|_|j|jjz|_dS)N)r __class____dict__ input_help output_help)selfs r8__init__zCryptoOperation.__init__wsCZ$."99 /DN,CC+dn.EEindatakeyr1cdS)zPerforms the program's operation. Implement in a subclass. :returns: the data to write to the output. N)rFrIrJr1s r8perform_operationz!CryptoOperation.perform_operation|srHc|\}}||d|j}||j}t |jtj | |||}|j r| ||j dSdS)zRuns the program.rrN) parse_cliread_keykeyform read_infileinputr#operation_progressivetitlerr$rM has_output write_outfileoutput)rFr0r1rJrIoutdatas r8__call__zCryptoOperation.__call__s..**hmmHQK55!!#),, d(..00szBBBB((h?? ? 4   w 3 3 3 3 3 4 4rHctj|j|j}|ddd|j|jr|ddd|j|dd |jzd d | tj d d\}}t||j kr#|td ||fS)zFParse the CLI options :returns: (cli_opts, cli_args) rz-iz--inputrr r z--outputz --keyformz&Key format of the %s key - default PEMr rrrN)rrrrrrDrVrEkeynamerrrrexpected_cli_argsrr )rFr/r0r1s r8rOzCryptoOperation.parse_clis &TZTEUVVV$ tOOO ? V   dJXDDT  U U U 9DLH"    !++CHQRRL99h x==D2 2 2      Q-- H}rHfilenamerQctd|jd|tjt |d5}|}dddn #1swxYwY|j||S)zReads a public or private key.zReading z key from rrbN)r#r\rr$r*read key_class load_pkcs1)rFr^rQkeyfilekeydatas r8rPzCryptoOperation.read_keys $,,,A SSSS (D ! ! %WllnnG % % % % % % % % % % % % % % %~((':::sAAAinnamec6|rZtd|ztjt|d5}|cdddS#1swxYwYtdtjtjjS)zRead the input filezReading input from %srr`NzReading input from stdin)r#rr$r*rastdinr.)rFrfinfiles r8rRzCryptoOperation.read_infiles  % )F2 D D D Dfd## %v{{}} % % % % % % % % % % % % % % % % (sz::::y$$&&&sAAArYoutnamecD|r^td|ztjt|d5}||ddddS#1swxYwYdStdtjtjj|dS)zWrite the output filezWriting output to %srrNzWriting output to stdout)r#rr$r*r+r-r.)rFrYrjr7s r8rWzCryptoOperation.write_outfiles  - (72 D D D Dgt$$ ' g&&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ,3: > > > > J  # #G , , , , ,sAAArN)%__name__ __module__ __qualname____doc__r\rr operationoperation_pastrTrDrEr]rVr% PublicKeyrbrGabcabstractmethodbytesrJ AbstractKey IndexabletypingAnyrMrZTuplerValuesListstrrOrPrRrWrLrHr8r;r;ds|CCG 5EKI N([J ?J IFFFF    "%'"5 AJ      4 4 4 46<S9I(IJ8;;s;sw7J;;;; '# '% ' ' ' ' -U -S -T - - - - - -rHr;) metaclassc VeZdZdZdZdZdZdZdZ dde d e j j d e d e fd Zd S)EncryptOperationzEncrypts a file.r<zWEncrypts a file. The file must be shorter than the key length in order to be encrypted.encrypt encrypted encryptingrLrIr4r1rcnt|tjjsJtj||S)zEncrypts files.) isinstancer%rJrsr)rFrIr4r1s r8rMz"EncryptOperation.perform_operations1'37#455555{67+++rHNrL)rmrnrorpr\rrqrrrTrvr%rJrwrxrMrLrHr8rrs~GdI N(RT,,,&)g&9,EN, ,,,,,,rHrc deZdZdZdZdZdZdZdZe j Z dde d e j jd ed e fd Zd S)DecryptOperationzDecrypts a file.privatezgDecrypts a file. The original file must be shorter than the key length in order to have been encrypted.r>r?r@rLrIr5r1rcnt|tjjsJtj||S)zDecrypts files.)rr%rJ PrivateKeyr>)rFrIr5r1s r8rMz"DecryptOperation.perform_operations1(CG$677777{68,,,rHNr)rmrnrorpr\rrqrrrTr%rrbrvrJrwrxrMrLrHr8rrsG :I N(ISU---'*w':-FO- ------rHrceZdZdZdZdZddezZdZ dZ dZ e j Zd Zd Zd ed e jjd edefdZdS) SignOperationz Signs a file.rz/usage: %%prog [options] private_key hash_methodzCSigns a file, outputs the signature. Choose the hash method from %s, sign signatureSigningz\Name of the file to write the signature to. Written to stdout if this option is not present.rIr5r1rct|tjjsJ|d}|tvr*t ddtztj|||S)z Signs files.rz%Invalid hash method, choose one of %sr)rr%rJr HASH_METHODSr joinr)rFrIr5r1 hash_methods r8rMzSignOperation.perform_operationsh(CG$677777qk l * *DtyyQ]G^G^^__ _x+666rHN)rmrnrorpr\rrrrrqrrrTr%rrbr]rErvrJrwrxrMrLrHr8rrsG =E 99\22 3I N%I 3 7 7'*w': 7FO 7  7 7 7 7 7 7rHrcleZdZdZdZdZdZdZdZdZ e j Z dZ d Zd ed e jjd ed dfdZdS)VerifyOperationzVerify 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.verifyverified VerifyingrFrIr4r1rNct|tjjsJ|d}t |d5}|}dddn #1swxYwY tj|||n'#tj$r}td|d}~wwxYwtdtj dS)zVerifies files.rr`NzVerification failed.zVerification OKr) rr%rJrsr*rarVerificationErrorr r#rr$)rFrIr4r1signature_filesigfilerr3s r8rMz!VerifyOperation.perform_operation+s'37#455555!! .$ ' ' '7 I ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' = Jvy' 2 2 2 2$ = = =344" < = cj111111s)AA"A'A>>B" BB")rmrnrorpr\rrrqrrrTr%rsrbr]rVrvrJrwrxrMrLrHr8rrsG ?E FIN' IJ22&)g&92EN2 222222rHrrl)rprtrryrr%rsa.key rsa.pkcs1sortedpkcs1rkeysUnionr{r}r~rxr9ABCMetar;rrrrrr>rrrLrHr8rs   vci,113344 Lv{3'77 8 @&@&@&@&Fk-k-k-k-k- k-k-k-k-\,,,,,,,,&--------*77777O777B 2 2 2 2 2o 2 2 2F        }   rH