Ñò
ðgcJc           @   s¶   d  Z  d d k l Z d d k l Z l Z d d k l Z d d k Td d k	 l
 Z
 d d k l Z d d k l Z l Z d d	 k l Z d d
 k l Z d e f d     YZ d S(   s   
L{RSAKey}
iÿÿÿÿ(   t   RSA(   t   SHAt   MD5(   t   DES3(   t   *(   t   util(   t   Message(   t   BERt   BERException(   t   PKey(   t   SSHExceptiont   RSAKeyc           B   sÅ   e  Z d  Z d d d d d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d d
  Z d d  Z d d  Z e e  Z d   Z d   Z d   Z d   Z RS(   sZ   
    Representation of an RSA key which can be used to sign and verify SSH2
    data.
    c         C   s5  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ | d  j	 o |  i | |  d  S| d  j	 o |  i | |  d  S| d  j o | d  j	 o t |  } n | d  j	 o | \ |  _ |  _ n_ | d  j o t	 d   n | i
   d j o t	 d   n | i   |  _ | i   |  _ t i |  i  |  _ d  S(   Ns   Key object may not be emptys   ssh-rsas   Invalid key(   t   Nonet   nt   et   dt   pt   qt   _from_private_keyt   _from_private_key_fileR   R
   t
   get_stringt	   get_mpintR   t
   bit_lengtht   size(   t   selft   msgt   datat   filenamet   passwordt   valst   file_obj(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   __init__)   s,    					c         C   s@   t    } | i d  | i |  i  | i |  i  t |  S(   Ns   ssh-rsa(   R   t
   add_stringt	   add_mpintR   R   t   str(   R   t   m(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   __str__B   s
    	c         C   sJ   t  |  i    } | d t  |  i  } | d t  |  i  } t  |  S(   Ni%   (   t   hasht   get_nameR   R   (   R   t   h(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   __hash__I   s    c         C   s   d S(   Ns   ssh-rsa(    (   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyR&   O   s    c         C   s   |  i  S(   N(   R   (   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   get_bitsR   s    c         C   s   |  i  d  j	 S(   N(   R   R   (   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   can_signU   s    c         C   s   t  i |  i   } t i t |  i  t |  i  t |  i  f  } t	 i
 | i |  i |  d  d d  } t   } | i d  | i |  | S(   Nt    i    s   ssh-rsa(   R   t   newt   digestR    t	   constructt   longR   R   R   R   t   deflate_longt   signt   _pkcs1imifyR   R    (   R   t   rpoolR   R-   t   rsat   sigR#   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   sign_ssh_dataX   s    3+	c         C   s   | i    d j o t St i | i    t  } t i |  i t i |  i    t  } t	 i
 t |  i  t |  i  f  } | i | | f  S(   Ns   ssh-rsa(   R   t   FalseR   t   inflate_longt   TrueR2   R   R,   R-   R    R.   R/   R   R   t   verify(   R   R   R   R5   t   hash_objR4   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   verify_ssh_siga   s    *'c         C   sÔ   |  i  d  j p |  i d  j o t d   n d |  i |  i |  i |  i  |  i |  i |  i  d |  i |  i d t i |  i |  i   g	 } y t	   } | i
 |  Wn t j
 o t d   n Xt |  S(   Ns-   Not enough key info to write private key filei    i   s$   Unable to create ber encoding of key(   R   R   R   R
   R   R   R   R   t   mod_inverseR   t   encodeR   R"   (   R   t   keylistt   b(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   _encode_keyl   s     !"	c         C   s    |  i  d | |  i   |  d  S(   NR    (   t   _write_private_key_fileRA   (   R   R   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   write_private_key_filey   s    c         C   s    |  i  d | |  i   |  d  S(   NR    (   t   _write_private_keyRA   (   R   R   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   write_private_key|   s    c         C   se   t  i   t i |  t  i |  } t d | i | i f  } | i | _ | i	 | _	 | i
 | _
 | S(   sÑ  
        Generate a new private RSA key.  This factory function can be used to
        generate a new host key or authentication key.

        @param bits: number of bits the generated key should be.
        @type bits: int
        @param progress_func: an optional function to call at key points in
            key generation (used by C{pyCrypto.PublicKey}).
        @type progress_func: function
        @return: new private key
        @rtype: L{RSAKey}
        R   (   t   randpoolt   stirR    t   generatet	   get_bytesR   R   R   R   R   R   (   t   bitst   progress_funcR4   t   key(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyRH      s    
c         C   sW   d } t  t i |  i d   } d | t  |  t  |  d } d | d | | S(   s   
        turn a 20-byte SHA1 hash into a blob of data as large as the key's N,
        using PKCS1's "emsa-pkcs1-v1_5" encoding.  totally bizarre.
        s   0!0	+ i    s   ÿi   t    t    (   t   lenR   R0   R   (   R   R   t   SHA1_DIGESTINFOR   t   filler(    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyR2      s    "c         C   s&   |  i  d | |  } |  i |  d  S(   NR    (   t   _read_private_key_filet   _decode_key(   R   R   R   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyR   £   s    c         C   s&   |  i  d | |  } |  i |  d  S(   NR    (   t   _read_private_keyRS   (   R   R   R   R   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyR   §   s    c         C   sÙ   y t  |  i   } Wn t j
 o t d   n Xt |  t j	 p$ t |  d j  p | d d j o t d   n | d |  _ | d |  _ | d |  _	 | d |  _
 | d |  _ t i |  i  |  _ d  S(	   Ns   Unable to parse key filei   i    s3   Not a valid RSA private key file (bad ber encoding)i   i   i   i   (   R   t   decodeR   R
   t   typet   listRO   R   R   R   R   R   R   R   R   (   R   R   R?   (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyRS   «   s    7N(   t   __name__t
   __module__t   __doc__R   R   R$   R(   R&   R)   R*   R6   R<   RA   RC   RE   RH   t   staticmethodR2   R   R   RS   (    (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyR   #   s$   										
		N(   RZ   t   Crypto.PublicKeyR    t   Crypto.HashR   R   t   Crypto.CipherR   t   paramiko.commont   paramikoR   t   paramiko.messageR   t   paramiko.berR   R   t   paramiko.pkeyR	   t   paramiko.ssh_exceptionR
   R   (    (    (    sN   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\rsakey.pyt   <module>   s   
