# Path: eulfedora/cryptutil.py
# ENCRYPTION_KEY = None
# ENCRYPT_PAD_CHARACTER = b'\0'
#         KEY_MIN_CHARS = 32/8
#         KEY_MAX_CHARS = 448/8
#             ENCRYPTION_KEY = settings.SECRET_KEY
#             ENCRYPTION_KEY = hashlib.sha224(settings.SECRET_KEY).hexdigest()
# def _get_encryption_key():
# def encrypt(text):
# def decrypt(text):
# def to_blocksize(password):
# 
# Path: eulfedora/util.py
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


import unittest
    import django
    from unittest import skipIf
    from unittest2 import skipIf
from eulfedora import cryptutil
from eulfedora.util import force_text


# NOTE: cryptutil currently requires django because it imports django
# settings for configuration; probably ok, since this is likely
# only used within django

@skipIf(django is None, 'Requires Django')
class CryptTest(unittest.TestCase):

    def test_to_blocksize(self):
        def test_valid_blocksize(text):
            block = cryptutil.to_blocksize(text)
            self.assertEqual(0, len(block) % cryptutil.EncryptionAlgorithm.block_size,
                '''text '%s' has correct block size for encryption algorithm''' % block)
            self.assert_(text in block, 'block-sized text contains original text')

        # test text of several sizes
        test_valid_blocksize('text')
        test_valid_blocksize('texty')
        test_valid_blocksize('textish')
        test_valid_blocksize('this is some text')
        test_valid_blocksize('this would be a really long password')
        test_valid_blocksize('can you imagine typing this every time you logged in?')

    def test_encrypt_decrypt(self):
        def test_encrypt_decrypt(text):
            encrypted = cryptutil.encrypt(text)
            self.assertNotEqual(text, encrypted,
                "encrypted text should not match original")
            decrypted = cryptutil.decrypt(encrypted)

# Path: eulfedora/cryptutil.py
# ENCRYPTION_KEY = None
# ENCRYPT_PAD_CHARACTER = b'\0'
#         KEY_MIN_CHARS = 32/8
#         KEY_MAX_CHARS = 448/8
#             ENCRYPTION_KEY = settings.SECRET_KEY
#             ENCRYPTION_KEY = hashlib.sha224(settings.SECRET_KEY).hexdigest()
# def _get_encryption_key():
# def encrypt(text):
# def decrypt(text):
# def to_blocksize(password):
# 
# Path: eulfedora/util.py
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


# Path: test/test_fedora/test_cryptutil.py
import unittest
    import django
    from unittest import skipIf
    from unittest2 import skipIf
from eulfedora import cryptutil
from eulfedora.util import force_text



# NOTE: cryptutil currently requires django because it imports django
# settings for configuration; probably ok, since this is likely
# only used within django

@skipIf(django is None, 'Requires Django')
class CryptTest(unittest.TestCase):

    def test_to_blocksize(self):
        def test_valid_blocksize(text):
            block = cryptutil.to_blocksize(text)
            self.assertEqual(0, len(block) % cryptutil.EncryptionAlgorithm.block_size,
                '''text '%s' has correct block size for encryption algorithm''' % block)
            self.assert_(text in block, 'block-sized text contains original text')

        # test text of several sizes
        test_valid_blocksize('text')
        test_valid_blocksize('texty')
        test_valid_blocksize('textish')
        test_valid_blocksize('this is some text')
        test_valid_blocksize('this would be a really long password')
        test_valid_blocksize('can you imagine typing this every time you logged in?')

    def test_encrypt_decrypt(self):
        def test_encrypt_decrypt(text):
            encrypted = cryptutil.encrypt(text)
            self.assertNotEqual(text, encrypted,
                "encrypted text should not match original")
            decrypted = cryptutil.decrypt(encrypted)

            self.assertEqual(text, force_text(decrypted),