
    Eh                      6    d Z ddlZddlZddl  G d d      Zy)z$Id$    N)*c                   |    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d Zy)pubkeyzxAn abstract class for a public key object.

    :undocumented: __getstate__, __setstate__, __eq__, __ne__, validate
    c                      y )N selfs    X/var/www/html/bid_assistant/venv/lib/python3.12/site-packages/Crypto/PublicKey/pubkey.py__init__zpubkey.__init__&   s        c                     | j                   }| j                  D ]%  }|j                  |      st        ||         ||<   ' |S )zTo 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.)__dict__keydatahas_keylongr	   dkeys      r
   __getstate__zpubkey.__getstate__)   s@    
 --<< 	3Cyy~d1S6lqv	3r   c                     | j                   D ]/  }|j                  |      st        ||         | j                  |<   1 y)zOn 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   bignumr   r   s      r
   __setstate__zpubkey.__setstate__3   s9     << 	ACyy~&3.t}}S1	Ar   c                     d}t        |t        j                        rt        |      }d}t        |t        j                        rt        |      }| j	                  ||      }|rt        t        t        |            S |S )aj  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).
        r      )
isinstancetypes
StringTypebytes_to_long_encrypttuplemaplong_to_bytes)r	   	plaintextK	wasString
ciphertexts        r
   encryptzpubkey.encrypt:   sk     	i!1!12#I.I1a))*AA==A.
U3}j#ABBr   c                     d}t        |t        j                        s|f}t        |d   t        j                        rt	        t        t        |            }d}| j                  |      }|rt        |      S |S )a.  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.
        r   r   )	r   r   	TupleTyper   r    r!   r   _decryptr"   )r	   r&   r%   r#   s       r
   decryptzpubkey.decryptO   sh     	*eoo6"}JjmU%5%56S
;<Jy--
+	]955r   c                     | j                         st        d      t        |t        j                        rt        |      }t        |t        j                        rt        |      }| j                  ||      S )a  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.
        z(Private key not available in this object)has_private	TypeErrorr   r   r   r   _sign)r	   Mr$   s      r
   signzpubkey.signa   s_       "FGGa))*mA.>Aa))*mA.>Azz!Qr   c                 p    t        |t        j                        rt        |      }| j	                  ||      S )a>  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   _verifyr	   r0   	signatures      r
   verifyzpubkey.verifyr   s.     a))*mA.>A||Ay))r   c                 8    t        j                  dt               y )Nz0validate() method name is obsolete; use verify())warningswarnDeprecationWarningr4   s      r
   validatezpubkey.validate   s    H(	*r   c                     d}t        |t        j                        rt        |      }d}t        |t        j                        rt        |      }| j	                  ||      }|rt        |      S |S )a&  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.
        r   r   )r   r   r   r   _blindr"   )r	   r0   Br%   blindedmessages        r
   blindzpubkey.blind   sc     	a))*AA1a))*mA.>A{{1a(]>::##r   c                     d}t        |t        j                        rt        |      }d}t        |t        j                        rt        |      }| j	                  ||      }|rt        |      S |S )zUnblind 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
        r   r   )r   r   r   r   _unblindr"   )r	   r0   r>   r%   unblindedmessages        r
   unblindzpubkey.unblind   se     	a))*AA1a))*mA.>Aq!,]+;<<%%r   c                      y)a(  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
        r   r   r   s    r
   can_signzpubkey.can_sign        r   c                      y)a  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
        r   r   r   s    r
   can_encryptzpubkey.can_encrypt   rG   r   c                      y)a  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
        r   r   r   s    r
   	can_blindzpubkey.can_blind   rG   r   c                      y)z_Tell the maximum number of bits that can be handled by this key.

        :Return: int
        r   r   r   s    r
   sizezpubkey.size       
 r   c                      y)zSTell if the key object contains private components.

        :Return: bool
        r   r   r   s    r
   r-   zpubkey.has_private   rN   r   c                     | S )zkConstruct a new key carrying only the public information.

        :Return: A new `pubkey` object.
        r   r   s    r
   	publickeyzpubkey.publickey   s	    
 r   c                 D    | j                         |j                         k(  S )zF__eq__(other): 0, 1
        Compare us to other for equality.
        )r   r	   others     r
   __eq__zpubkey.__eq__   s!       "e&8&8&:::r   c                 &    | j                  |       S )zH__ne__(other): 0, 1
        Compare us to other for inequality.
        )rU   rS   s     r
   __ne__zpubkey.__ne__   s     ;;u%%%r   N)__name__
__module____qualname____doc__r   r   r   r'   r+   r1   r6   r;   r@   rD   rF   rI   rK   rM   r-   rQ   rU   rW   r   r   r
   r   r   !   sb    A *$ "**$&&*			;&r   r   )__revision__r   r8   Crypto.Util.numberr   r   r   r
   <module>r^      s   6    O& O&r   