home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2249 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.1 KB  |  145 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __revision__ = '$Id: pubkey.py,v 1.11 2003/04/03 20:36:14 akuchling Exp $'
  5. import types
  6. import warnings
  7. from Crypto.Util.number import *
  8.  
  9. class pubkey:
  10.     
  11.     def __init__(self):
  12.         pass
  13.  
  14.     
  15.     def __getstate__(self):
  16.         d = self.__dict__
  17.         for key in self.keydata:
  18.             if d.has_key(key):
  19.                 d[key] = long(d[key])
  20.                 continue
  21.         
  22.         return d
  23.  
  24.     
  25.     def __setstate__(self, d):
  26.         for key in self.keydata:
  27.             if d.has_key(key):
  28.                 self.__dict__[key] = bignum(d[key])
  29.                 continue
  30.         
  31.  
  32.     
  33.     def encrypt(self, plaintext, K):
  34.         wasString = 0
  35.         if isinstance(plaintext, types.StringType):
  36.             plaintext = bytes_to_long(plaintext)
  37.             wasString = 1
  38.         
  39.         if isinstance(K, types.StringType):
  40.             K = bytes_to_long(K)
  41.         
  42.         ciphertext = self._encrypt(plaintext, K)
  43.         if wasString:
  44.             return tuple(map(long_to_bytes, ciphertext))
  45.         return ciphertext
  46.  
  47.     
  48.     def decrypt(self, ciphertext):
  49.         wasString = 0
  50.         if not isinstance(ciphertext, types.TupleType):
  51.             ciphertext = (ciphertext,)
  52.         
  53.         if isinstance(ciphertext[0], types.StringType):
  54.             ciphertext = tuple(map(bytes_to_long, ciphertext))
  55.             wasString = 1
  56.         
  57.         plaintext = self._decrypt(ciphertext)
  58.         if wasString:
  59.             return long_to_bytes(plaintext)
  60.         return plaintext
  61.  
  62.     
  63.     def sign(self, M, K):
  64.         if not self.has_private():
  65.             raise error, 'Private key not available in this object'
  66.         self.has_private()
  67.         if isinstance(M, types.StringType):
  68.             M = bytes_to_long(M)
  69.         
  70.         if isinstance(K, types.StringType):
  71.             K = bytes_to_long(K)
  72.         
  73.         return self._sign(M, K)
  74.  
  75.     
  76.     def verify(self, M, signature):
  77.         if isinstance(M, types.StringType):
  78.             M = bytes_to_long(M)
  79.         
  80.         return self._verify(M, signature)
  81.  
  82.     
  83.     def validate(self, M, signature):
  84.         warnings.warn('validate() method name is obsolete; use verify()', DeprecationWarning)
  85.  
  86.     
  87.     def blind(self, M, B):
  88.         wasString = 0
  89.         if isinstance(M, types.StringType):
  90.             M = bytes_to_long(M)
  91.             wasString = 1
  92.         
  93.         if isinstance(B, types.StringType):
  94.             B = bytes_to_long(B)
  95.         
  96.         blindedmessage = self._blind(M, B)
  97.         if wasString:
  98.             return long_to_bytes(blindedmessage)
  99.         return blindedmessage
  100.  
  101.     
  102.     def unblind(self, M, B):
  103.         wasString = 0
  104.         if isinstance(M, types.StringType):
  105.             M = bytes_to_long(M)
  106.             wasString = 1
  107.         
  108.         if isinstance(B, types.StringType):
  109.             B = bytes_to_long(B)
  110.         
  111.         unblindedmessage = self._unblind(M, B)
  112.         if wasString:
  113.             return long_to_bytes(unblindedmessage)
  114.         return unblindedmessage
  115.  
  116.     
  117.     def can_sign(self):
  118.         return 1
  119.  
  120.     
  121.     def can_encrypt(self):
  122.         return 1
  123.  
  124.     
  125.     def can_blind(self):
  126.         return 0
  127.  
  128.     
  129.     def size(self):
  130.         return 0
  131.  
  132.     
  133.     def has_private(self):
  134.         return 0
  135.  
  136.     
  137.     def publickey(self):
  138.         return self
  139.  
  140.     
  141.     def __eq__(self, other):
  142.         return self.__getstate__() == other.__getstate__()
  143.  
  144.  
  145.