
/Oc           @   s?   d  Z  d d l Z d d l Z d d l Td d d     YZ d S(   s   $Id$iN(   t   *t   pubkeyc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sx   An abstract class for a public key object.

    :undocumented: __getstate__, __setstate__, __eq__, __ne__, validate
    c         C   s   d  S(   N(    (   t   self(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   __init__&   s    c         C   sG   |  j  } x7 |  j D], } | j |  r t | |  | | <q q W| S(   s   To keep key objects platform-independent, the key data is
        converted to standard Python long integers before being
        written out.  It will then be reconverted as necessary on
        restoration.(   t   __dict__t   keydatat   has_keyt   long(   R   t   dt   key(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   __getstate__)   s
    	 c         C   sA   x: |  j  D]/ } | j |  r
 t | |  |  j | <q
 q
 Wd S(   s   On unpickling a key object, the key data is converted to the big
number representation being used, whether that is Python long
integers, MPZ objects, or whatever.N(   R   R   t   bignumR   (   R   R   R	   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   __setstate__3   s     c         C   s   d } t  | t j  r- t |  } d } n  t  | t j  rN t |  } n  |  j | |  } | ry t t t |   S| Sd S(   sj  Encrypt a piece of data.

        :Parameter plaintext: The piece of data to encrypt.
        :Type plaintext: byte string or long

        :Parameter K: A random parameter required by some algorithms
        :Type K: byte string or long

        :Return: A tuple with two items. Each item is of the same type as the
         plaintext (string or long).
        i    i   N(   t
   isinstancet   typest
   StringTypet   bytes_to_longt   _encryptt   tuplet   mapt   long_to_bytes(   R   t	   plaintextt   Kt	   wasStringt
   ciphertext(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   encrypt:   s     	 c         C   s   d } t  | t j  s$ | f } n  t  | d t j  rX t t t |   } d } n  |  j |  } | rw t |  S| Sd S(   s.  Decrypt a piece of data. 

        :Parameter ciphertext: The piece of data to decrypt.
        :Type ciphertext: byte string, long or a 2-item tuple as returned by `encrypt`

        :Return: A byte string if ciphertext was a byte string or a tuple
         of byte strings. A long otherwise.
        i    i   N(	   R   R   t	   TupleTypeR   R   R   R   t   _decryptR   (   R   R   R   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   decryptO   s    	 	 
c         C   sm   |  j    s t d   n  t | t j  r< t |  } n  t | t j  r] t |  } n  |  j | |  S(   s  Sign a piece of data.

        :Parameter M: The piece of data to encrypt.
        :Type M: byte string or long

        :Parameter K: A random parameter required by some algorithms
        :Type K: byte string or long

        :Return: A tuple with two items.
        s(   Private key not available in this object(   t   has_privatet	   TypeErrorR   R   R   R   t   _sign(   R   t   MR   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   signa   s      c         C   s1   t  | t j  r! t |  } n  |  j | |  S(   s>  Verify the validity of a signature.

        :Parameter M: The expected message.
        :Type M: byte string or long

        :Parameter signature: The signature to verify.
        :Type signature: tuple with two items, as return by `sign`

        :Return: True if the signature is correct, False otherwise.
        (   R   R   R   R   t   _verify(   R   R    t	   signature(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   verifyr   s     c         C   s   t  j d t  d  S(   Ns0   validate() method name is obsolete; use verify()(   t   warningst   warnt   DeprecationWarning(   R   R    R#   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   validate   s    	c         C   sx   d } t  | t j  r- t |  } d } n  t  | t j  rN t |  } n  |  j | |  } | rp t |  S| Sd S(   s&  Blind a message to prevent certain side-channel attacks.
       
        :Parameter M: The message to blind.
        :Type M: byte string or long

        :Parameter B: Blinding factor.
        :Type B: byte string or long

        :Return: A byte string if M was so. A long otherwise.
        i    i   N(   R   R   R   R   t   _blindR   (   R   R    t   BR   t   blindedmessage(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   blind   s     	  
c         C   sx   d } t  | t j  r- t |  } d } n  t  | t j  rN t |  } n  |  j | |  } | rp t |  S| Sd S(   s   Unblind a message after cryptographic processing.
        
        :Parameter M: The encoded message to unblind.
        :Type M: byte string or long

        :Parameter B: Blinding factor.
        :Type B: byte string or long
        i    i   N(   R   R   R   R   t   _unblindR   (   R   R    R*   R   t   unblindedmessage(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   unblind   s    	 	  
c         C   s   d S(   s(  Tell if the algorithm can deal with cryptographic signatures.

        This property concerns the *algorithm*, not the key itself.
        It may happen that this particular key object hasn't got
        the private information required to generate a signature.

        :Return: boolean
        i   (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   can_sign   s    	c         C   s   d S(   s  Tell if the algorithm can deal with data encryption.
       
        This property concerns the *algorithm*, not the key itself.
        It may happen that this particular key object hasn't got
        the private information required to decrypt data.

        :Return: boolean
        i   (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   can_encrypt   s    	c         C   s   d S(   s  Tell if the algorithm can deal with data blinding.
       
        This property concerns the *algorithm*, not the key itself.
        It may happen that this particular key object hasn't got
        the private information required carry out blinding.

        :Return: boolean
        i    (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt	   can_blind   s    	c         C   s   d S(   s_   Tell the maximum number of bits that can be handled by this key.

        :Return: int
        i    (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   size   s    c         C   s   d S(   sS   Tell if the key object contains private components.

        :Return: bool
        i    (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyR      s    c         C   s   |  S(   sk   Construct a new key carrying only the public information.

        :Return: A new `pubkey` object.
        (    (   R   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt	   publickey   s    c         C   s   |  j    | j    k S(   sF   __eq__(other): 0, 1
        Compare us to other for equality.
        (   R
   (   R   t   other(    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   __eq__   s    c         C   s   |  j  |  S(   sH   __ne__(other): 0, 1
        Compare us to other for inequality.
        (   R6   (   R   R5   (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   __ne__   s    (   t   __name__t
   __module__t   __doc__R   R
   R   R   R   R!   R$   R(   R,   R/   R0   R1   R2   R3   R   R4   R6   R7   (    (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyR   !   s&   		
															(    (   t   __revision__R   R%   t   Crypto.Util.numberR   (    (    (    s6   lib/python2.7/site-packages/Crypto/PublicKey/pubkey.pyt   <module>   s   
