示例#1
0
 def test_crypt_order_doesnt_matter(self):
     # blockalgo.py has a concerning comment indicating that the cipher may be stateful,
     # and that we shouldn't be re-using the cipher object. However, empirical data
     # shows that re-using the cipher object does not cause any problems. This test
     # verifies that whatever internal state the cipher object may maintain does
     # not affect the cipher text.
     crypted_msgs = {msg: crypt.encrypt(msg) for msg in self.TEST_MSGS}
     # Reset to a new cipher
     crypt.cipher = AES.new(settings.UTIL_CRYPT_CIPHER)
     self.TEST_MSGS.reverse()
     crypted_in_reverse = {msg: crypt.encrypt(msg) for msg in self.TEST_MSGS}
     [self.assertEqual(crypted_msgs[msg],
                       crypted_in_reverse[msg]) for msg in self.TEST_MSGS]
示例#2
0
 def test_crypt_order_doesnt_matter(self):
     # This is effectively a test that we are using ECB (or some other non-chained)
     # mode of operation, because as long as we are it's fine to keep using the same
     # cipher object over and over. If we switched to a chained mode, this test would
     # break and we would need to create a new cipher object (and IV and/or nonce,
     # depending on mode) for every message.
     crypted_msgs = {msg: crypt.encrypt(msg) for msg in self.msgs}
     # Reset to a new cipher
     crypt._set_cipher()
     self.msgs.reverse()
     crypted_in_reverse = {msg: crypt.encrypt(msg) for msg in self.msgs}
     [
         self.assertEqual(crypted_msgs[msg], crypted_in_reverse[msg])
         for msg in self.msgs
     ]
示例#3
0
    def encode(self):
        """Custom encoding for Kale tasks.

        :return: string for encoded message.
        :rtype: str
        """

        compressed_msg = _compressor(
            pickle.dumps(self._get_message_body(), protocol=settings.PICKLE_PROTOCOL))
        compressed_msg = crypt.encrypt(compressed_msg)
        # Check compressed task size.
        if len(compressed_msg) >= _task_size_limit:
            raise exceptions.ChubbyTaskException(
                'Task %s is over the limit of %d bytes.' % (self.task_id,
                                                            _task_size_limit))

        return compressed_msg.decode("utf-8")
示例#4
0
    def encode(self, msg):
        """Custom encoding for Kale tasks.

        :param dict msg: message to decode.
        :return: string for encoded message.
        :rtype: str
        """

        compressed_msg = _compressor(pickle.dumps(msg))
        compressed_msg = crypt.encrypt(compressed_msg)
        # Check compressed task size.
        if len(compressed_msg) >= _task_size_limit:
            task_id = msg.get('task_id')
            raise exceptions.ChubbyTaskException(
                'Task %s is over the limit of %d bytes.' %
                (task_id, _task_size_limit))

        return compressed_msg
示例#5
0
文件: message.py 项目: Kaleva/ndkale
    def encode(self, msg):
        """Custom encoding for Kale tasks.

        :param dict msg: message to decode.
        :return: string for encoded message.
        :rtype: str
        """

        compressed_msg = _compressor(pickle.dumps(msg))
        compressed_msg = crypt.encrypt(compressed_msg)
        # Check compressed task size.
        if len(compressed_msg) >= _task_size_limit:
            task_id = msg.get('task_id')
            raise exceptions.ChubbyTaskException(
                'Task %s is over the limit of %d bytes.' % (task_id,
                                                            _task_size_limit))

        return compressed_msg
示例#6
0
 def test_decrypt(self):
     for msg in self.msgs:
         crypted_msg = crypt.encrypt(msg)
         self.assertEqual(msg, crypt.decrypt(crypted_msg))
示例#7
0
 def test_crypt(self):
     for msg in self.msgs:
         self.assertNotEqual(msg, crypt.encrypt(msg))
示例#8
0
 def test_decrypt(self):
     crypted_msgs = {msg: crypt.encrypt(msg) for msg in self.TEST_MSGS}
     [self.assertEqual(msg, crypt.decrypt(crypted_msg)) for msg, crypted_msg
      in crypted_msgs.iteritems()]
示例#9
0
 def test_crypt(self):
     [self.assertNotEqual(msg,
                          crypt.encrypt(msg)) for msg in self.TEST_MSGS]
示例#10
0
 def test_decrypt(self):
     for msg in self.TEST_MSGS:
         crypted_msg = crypt.encrypt(msg)
         self.assertEqual(msg, crypt.decrypt(crypted_msg))