File: //usr/lib/python3.6/site-packages/rsa/__pycache__/util.cpython-36.opt-1.pyc
3
�Cb` � @ s2 d Z ddlZddlmZ ddlZdd�dd�ZdS )zUtility functions.� N)�OptionParser)�returnc C sr t ddd�} | jdddddd � | jd
dddd
d � | jdddd dd� | jdddd!dd� | jtj�\}}|jr�td|j|jf tjd� t |jd��}|j
� }W dQ R X n$td|j tjd� tjj
� jd�}t
jjj||j�}t
jj|j|j�}|j|j�}|j�rHtd|j|jf tjd� t |jd��}|j|� W dQ R X n&td|j tjd� tjj|jd�� dS )"z=Reads a private key and outputs the corresponding public key.zusage: %prog [options]z�Reads a private key and outputs the corresponding public key. Both private and public keys use the format described in PKCS#1 v1.5)Zusage�descriptionz-iz--input�
infilename�stringz1Input filename. Reads from stdin if not specified)�dest�type�helpz-oz--output�outfilenamez2Output filename. Writes to stdout of not specifiedz--inform�informz!key format of input - default PEM�PEM�DER)r r �choices�defaultz --outform�outformz"key format of output - default PEMz(Reading private key from %s in %s format)�file�rbNz+Reading private key from stdin in %s format�asciiz%Writing public key to %s in %s format�wbz)Writing public key to stdout in %s format)r r
)r r
)r Z
add_option�
parse_args�sys�argvr �printr �stderr�open�read�stdin�encode�rsa�keyZ
PrivateKeyZ
load_pkcs1Z PublicKey�n�eZ
save_pkcs1r r
�write�stdout�decode) �parserZcliZcli_argsZinfileZin_dataZpriv_keyZpub_keyZout_dataZoutfile� r&