# Path: kale/crypt.py
# BLOCK_SIZE = 16
# def _set_cipher():
# def encrypt(msg):
# def decrypt(msg):
# def urlsafe_encrypt(msg):
# def hex_encrypt(msg):
# def hex_decrypt(msg):
# def urlsafe_decrypt(msg):
# def _pad(msg):
# def _get_padding_bytes(msg_length):
# def _unpad(msg):
# class CryptException(Exception):


import unittest
from kale import crypt
        # 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]

    def test_bad_decryption_input(self):
        """Test that we get CryptException when we pass bad input to decrypt functions."""
        bad_messages = ['#$##$#$#$#$#',  # Just garbage
                        'abcdefABCDEF00==',  # base64 encoded garbage
                        'BYx3EzvPWTMLkBA5FF4xWw==',  # message with the padding byte > BLOCK_SIZE
                        'Hn+Ou2DpitXxWD47glRtJw==',  # message with the padding byte > message size
                        # more base64 encoded garbage
                        'QkJCQkJCQkJBQUFBQUFBQWFiY19lZkFCQ0RFRiUlAAE='
                        ]

        for f in [crypt.decrypt, crypt.hex_decrypt, crypt.urlsafe_decrypt]:
            for msg in bad_messages:
                with self.assertRaises(crypt.CryptException):
                    f(msg)

    def test_bad_encryption_input(self):
        """Test that we raise ValueError when we are passed bad input to encrypt functions."""

# Path: kale/crypt.py
# BLOCK_SIZE = 16
# def _set_cipher():
# def encrypt(msg):
# def decrypt(msg):
# def urlsafe_encrypt(msg):
# def hex_encrypt(msg):
# def hex_decrypt(msg):
# def urlsafe_decrypt(msg):
# def _pad(msg):
# def _get_padding_bytes(msg_length):
# def _unpad(msg):
# class CryptException(Exception):


# Path: kale/tests/test_crypt.py
import unittest
from kale import crypt

        # 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]

    def test_bad_decryption_input(self):
        """Test that we get CryptException when we pass bad input to decrypt functions."""
        bad_messages = ['#$##$#$#$#$#',  # Just garbage
                        'abcdefABCDEF00==',  # base64 encoded garbage
                        'BYx3EzvPWTMLkBA5FF4xWw==',  # message with the padding byte > BLOCK_SIZE
                        'Hn+Ou2DpitXxWD47glRtJw==',  # message with the padding byte > message size
                        # more base64 encoded garbage
                        'QkJCQkJCQkJBQUFBQUFBQWFiY19lZkFCQ0RFRiUlAAE='
                        ]

        for f in [crypt.decrypt, crypt.hex_decrypt, crypt.urlsafe_decrypt]:
            for msg in bad_messages:
                with self.assertRaises(crypt.CryptException):
                    f(msg)

    def test_bad_encryption_input(self):
        """Test that we raise ValueError when we are passed bad input to encrypt functions."""

        bad_input = [crypt.CryptException(),  # not a str