コード例 #1
0
 def test_encrypt_decrypt(self):
     key1 = "12345678"
     key2 = "12345679"
     for text in ("some text", "blabla", "12=213"):
         encrypted_text = encrypt(text, key1)
         self.assertEqual(text, decrypt(encrypted_text, key1))
         self.assertNotEqual(text, decrypt(encrypted_text, key2))
コード例 #2
0
    def check_token(self, token):
        """Check that the token is valid"""
        message = crypto.decrypt(token, self.encryption_key)
        match = re.match(r"^(\d+):%s$" % self.signature, message)
        if match:
            timestamp = int(match.group(1))
            token_date = datetime.fromtimestamp(timestamp)
            deadline = token_date + self.expiration_delay
            now = datetime.now()
            self.log.debug('Token date: %s' % token_date)
            if (now > token_date) and (now < deadline):
                return True

        return False
コード例 #3
0
 def test_decrypt(self):
     self.assertEquals("", decrypt("abc", "12345678"))