HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/rsa/__pycache__/cli.cpython-36.opt-1.pyc
3

<�a�'�@s�dZddlZddlZddlZddlZddlZddlZddlZeej	j
j��Z
ejej
ejefZdd�dd�ZGdd�dejd�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�Ze�Ze�Ze�Ze�ZdS)zWCommandline scripts.

These scripts are called by the executables defined in setup.py.
�N)�returnc	Cs�tjddd�}|jdddd�|jdd	dd
d�|jdddd
d�|jtjdd��\}}t|�dkrv|j�td��yt	|d�}WnJt
k
r�}z.|j�td|dtjd�td�|�WYdd}~XnXtd|tjd�t
j|�\}}|j�r>td|jtjd�|j|jd�}t|jd��}|j|�WdQRX|j|jd�}|j�r�td|jtjd�t|jd��}|j|�WdQRXntdtjd�tjjj|�dS)zKey generator.zusage: %prog [options] keysizez/Generates a new RSA key pair of "keysize" bits.)�usage�descriptionz--pubout�stringz�Output 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�helpz-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�DER)r�choices�default�NrzNot a valid number: %s)�filezGenerating %i-bit keyzWriting public key to %s)�format�wbzWriting private key to %szWriting private key to stdout)rr	)�optparse�OptionParser�
add_option�
parse_args�sys�argv�len�
print_help�
SystemExit�int�
ValueError�print�stderr�rsaZnewkeysZpuboutZ
save_pkcs1Zform�open�write�out�stdout�buffer)	�parser�cli�cli_argsZkeysize�ex�pub_key�priv_key�data�outfile�r+�/usr/lib/python3.6/cli.py�keygen!sRr-c@s�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
ejZdd
�dd�Zejeejjeejd�dd��Zdd
�dd�Zejejeje fd
�dd�Z!e e ejjd�dd�Z"e ed�dd�Z#ee dd�dd�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TN)rcCs4|j|jj|_|j|jj|_|j|jj|_dS)N)r�	__class__�__dict__�
input_help�output_help)�selfr+r+r,�__init__wszCryptoOperation.__init__)�indata�keyr%rcCsdS)z�Performs the program's operation.

        Implement in a subclass.

        :returns: the data to write to the output.
        Nr+)r8r:r;r%r+r+r,�perform_operation|sz!CryptoOperation.perform_operationcCsd|j�\}}|j|d|j�}|j|j�}t|jj�tj	d�|j
|||�}|jr`|j||j
�dS)zRuns the program.r)r
N)�	parse_cli�read_key�keyform�read_infile�inputr�operation_progressive�titlerrr<�
has_output�
write_outfile�output)r8r$r%r;r:�outdatar+r+r,�__call__�szCryptoOperation.__call__cCs�tj|j|jd�}|jddd|jd�|jr@|jddd|jd�|jdd	|jdd
d�|j	t
jd
d��\}}t|�|j
kr�|j�td
��||fS)zFParse the CLI options

        :returns: (cli_opts, cli_args)
        )rrz-iz--inputr)rrz-oz--outputz	--keyformz&Key format of the %s key - default PEMrr	)rr
rrN)rr	)rrrrrr6rDr7�keynamerrrr�expected_cli_argsrr)r8r#r$r%r+r+r,r=�szCryptoOperation.parse_cli)�filenamer?rc
CsDtd|j|ftjd�t|d��}|j�}WdQRX|jj||�S)zReads a public or private key.zReading %s key from %s)r
�rbN)rrIrrr�read�	key_classZ
load_pkcs1)r8rKr?ZkeyfileZkeydatar+r+r,r>�szCryptoOperation.read_key)�innamercCsJ|r0td|tjd�t|d��
}|j�SQRXtdtjd�tjjj�S)zRead the input filezReading input from %s)r
rLNzReading input from stdin)rrrrrM�stdinr")r8rOZinfiler+r+r,r@�szCryptoOperation.read_infile)rG�outnamerc	CsX|r8td|tjd�t|d��}|j|�WdQRXntdtjd�tjjj|�dS)zWrite the output filezWriting output to %s)r
rNzWriting output to stdout)rrrrrr!r")r8rGrQr*r+r+r,rE�szCryptoOperation.write_outfile)%�__name__�
__module__�__qualname__�__doc__rIrr�	operation�operation_pastrBr6r7rJrDr�	PublicKeyrNr9�abc�abstractmethod�bytesr;�AbstractKey�	Indexable�typingZAnyr<rH�TuplerZValues�List�strr=r>r@rEr+r+r+r,r.ds*
 	r.)�	metaclassc@s@eZdZdZdZdZdZdZdZffe	e
jje
e	d�dd	�Zd
S)�EncryptOperationzEncrypts a file.r/zWEncrypts a file. The file must be shorter than the key length in order to be encrypted.�encryptZ	encryptedZ
encrypting)r:r'r%rcCstj||�S)zEncrypts files.)rrd)r8r:r'r%r+r+r,r<�sz"EncryptOperation.perform_operationN)rRrSrTrUrIrrVrWrBr[rr;r\r]r<r+r+r+r,rc�srcc@sFeZdZdZdZdZdZdZdZe	j
Zffee	j
jeed�dd	�Zd
S)�DecryptOperationzDecrypts a file.�privatezgDecrypts a file. The original file must be shorter than the key length in order to have been encrypted.r1r2r3)r:r(r%rcCstj||�S)zDecrypts files.)rr1)r8r:r(r%r+r+r,r<�sz"DecryptOperation.perform_operationN)rRrSrTrUrIrrVrWrBr�
PrivateKeyrNr[r;r\r]r<r+r+r+r,re�srec@sXeZdZdZdZdZddje�ZdZ	dZ
dZej
Zd	Zd
Zeejjeed�dd
�ZdS)�
SignOperationz
Signs a file.rfz/usage: %%prog [options] private_key hash_methodzCSigns a file, outputs the signature. Choose the hash method from %sz, �sign�	signatureZSigning�z\Name of the file to write the signature to. Written to stdout if this option is not present.)r:r(r%rcCs0|d}|tkr"tddjt���tj|||�S)zSigns files.rz%Invalid hash method, choose one of %sz, )�HASH_METHODSr�joinrri)r8r:r(r%Zhash_methodr+r+r,r<szSignOperation.perform_operationN)rRrSrTrUrIrrmrlrrVrWrBrrgrNrJr7r[r;r\r]r<r+r+r+r,rh�s
rhc@sNeZdZdZdZdZdZdZdZdZ	e
jZdZ
d	Zee
jjed
d�dd
�Zd
S)�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.�verifyZverifiedZ	VerifyingrkFN)r:r'r%rcCsz|d}t|d��}|j�}WdQRXytj|||�Wn.tjk
rf}ztd�|�WYdd}~XnXtdtjd�dS)zVerifies files.rrLNzVerification failed.zVerification OK)r
)	rrMrroZVerificationErrorrrrr)r8r:r'r%Zsignature_fileZsigfilerjr&r+r+r,r<+sz!VerifyOperation.perform_operation)rRrSrTrUrIrrrVrWrBrrXrNrJrDr[r;r\r]r<r+r+r+r,rns
rn)rUrYrr^rrZrsa.keyZ	rsa.pkcs1�sortedZpkcs1rl�keysZUnionr_r`rar]r-�ABCMetar.rcrerhrnrdr1riror+r+r+r,�<module>s&Cn!#