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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import warnings as _warnings
  5. trans_5C = []([ chr(x ^ 92) for x in xrange(256) ])
  6. trans_36 = []([ chr(x ^ 54) for x in xrange(256) ])
  7. digest_size = None
  8. _secret_backdoor_key = []
  9.  
  10. class HMAC:
  11.     blocksize = 64
  12.     
  13.     def __init__(self, key, msg = None, digestmod = None):
  14.         if key is _secret_backdoor_key:
  15.             return None
  16.         if digestmod is None:
  17.             import hashlib
  18.             digestmod = hashlib.md5
  19.         
  20.         if hasattr(digestmod, '__call__'):
  21.             self.digest_cons = digestmod
  22.         else:
  23.             
  24.             self.digest_cons = lambda d = ('',): digestmod.new(d)
  25.         self.outer = self.digest_cons()
  26.         self.inner = self.digest_cons()
  27.         self.digest_size = self.inner.digest_size
  28.         if hasattr(self.inner, 'block_size'):
  29.             blocksize = self.inner.block_size
  30.             if blocksize < 16:
  31.                 _warnings.warn('block_size of %d seems too small; using our default of %d.' % (blocksize, self.blocksize), RuntimeWarning, 2)
  32.                 blocksize = self.blocksize
  33.             
  34.         else:
  35.             _warnings.warn('No block_size attribute on given digest object; Assuming %d.' % self.blocksize, RuntimeWarning, 2)
  36.             blocksize = self.blocksize
  37.         if len(key) > blocksize:
  38.             key = self.digest_cons(key).digest()
  39.         
  40.         key = key + chr(0) * (blocksize - len(key))
  41.         self.outer.update(key.translate(trans_5C))
  42.         self.inner.update(key.translate(trans_36))
  43.         if msg is not None:
  44.             self.update(msg)
  45.         
  46.  
  47.     
  48.     def update(self, msg):
  49.         self.inner.update(msg)
  50.  
  51.     
  52.     def copy(self):
  53.         other = self.__class__(_secret_backdoor_key)
  54.         other.digest_cons = self.digest_cons
  55.         other.digest_size = self.digest_size
  56.         other.inner = self.inner.copy()
  57.         other.outer = self.outer.copy()
  58.         return other
  59.  
  60.     
  61.     def _current(self):
  62.         h = self.outer.copy()
  63.         h.update(self.inner.digest())
  64.         return h
  65.  
  66.     
  67.     def digest(self):
  68.         h = self._current()
  69.         return h.digest()
  70.  
  71.     
  72.     def hexdigest(self):
  73.         h = self._current()
  74.         return h.hexdigest()
  75.  
  76.  
  77.  
  78. def new(key, msg = None, digestmod = None):
  79.     return HMAC(key, msg, digestmod)
  80.  
  81.