Esempio n. 1
0
 def encode(self, value):
     """ Identity encoding (str->str) with signature """
     if self._signkey:
         from Crypto.Hash import HMAC
         value = _sharedance.escape(
             HMAC.new(self._signkey, value).digest()[:8]
         ) + value
     return value
Esempio n. 2
0
 def decode(self, value):
     """ Identity decoding (str->str) with integrity checking """
     if self._signkey:
         sign, value = value[:11], value[11:] # 11 = 8 * 4/3 - padding
         from Crypto.Hash import HMAC
         if _sharedance.escape(
                 HMAC.new(self._signkey, value).digest()[:8]) != sign:
             raise ValueError()
     return value
Esempio n. 3
0
 def _gensid(self):
     """ Generate a random session ID """
     numbytes, rest = divmod(self._SIDLEN * 3, 4)
     numbytes += int(bool(rest))
     return _sharedance.escape(_os.urandom(numbytes))[:self._SIDLEN]