o
    9F9`                     @   s.   d Z ddlZddlmZ ddlZdddZdS )zUtility functions.    N)OptionParserreturnc            	      C   s  t ddd} | jdddddd	 | jd
ddddd	 | jdddddd | jdddddd | tj\}}|jratd|j|jf tjd t	|jd}|
 }W d   n1 s[w   Y  ntd|j tjd tj
 d}t|tksJ t|tjj||j}tj|j|j}||j}|jrtd|j|jf tjd t	|jd}|| W d   dS 1 sw   Y  dS td|j tjd tj|d dS ) z=Reads a private key and outputs the corresponding public key.zusage: %prog [options]zReads a private key and outputs the corresponding public key. Both private and public keys use the format described in PKCS#1 v1.5)usage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)PEMZDERr   )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   Z
add_option
parse_argssysargvr   printr   stderropenreadstdinencoder	   bytesrsakeyZ
PrivateKeyZ
load_pkcs1Z	PublicKeyneZ
save_pkcs1r   r   writestdoutdecode)	parserZcliZcli_argsZinfileZin_dataZpriv_keyZpub_keyZout_dataZoutfile r'   (lib/python3.10/site-packages/rsa/util.pyprivate_to_public   sb   



"
r)   )r   N)__doc__r   Zoptparser   Zrsa.keyr   r)   r'   r'   r'   r(   <module>   s
   