work on tests and pack improvements

This commit is contained in:
Kevin Froman 2020-04-12 19:53:57 -05:00
parent 6143218d7a
commit 5e7ee4ad69
3 changed files with 19 additions and 5 deletions

View File

@ -24,10 +24,14 @@ def pack(data: bytes, data_type: 'KastenDataType',
if not data_type or len(data_type) > 4: if not data_type or len(data_type) > 4:
raise exceptions.InvalidKastenTypeLength raise exceptions.InvalidKastenTypeLength
# Ensure encryption mode is valid (asymmetric, symmetric, plaintext) # Ensure encryption mode is in [0, 100)
try:
enc_mode = int(enc_mode) enc_mode = int(enc_mode)
if enc_mode not in range(3): except (TypeError, ValueError):
raise raise exceptions.InvalidEncryptionMode
if not enc_mode >= 0 or enc_mode >= 100:
raise exceptions.InvalidEncryptionMode
try: try:
data = data.encode('utf8') data = data.encode('utf8')
except AttributeError: except AttributeError:

View File

@ -12,7 +12,8 @@ setup(name='kasten',
author_email='beardog@mailbox.org', author_email='beardog@mailbox.org',
url='https://chaoswebs.net', url='https://chaoswebs.net',
packages=find_packages(exclude=['contrib', 'docs', 'tests']), packages=find_packages(exclude=['contrib', 'docs', 'tests']),
install_requires=['mimcvdf', 'msgpack'], python_requires='>3.6.0',
install_requires=['msgpack', 'mimcvdf'],
long_description=long_description, long_description=long_description,
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
classifiers=[ classifiers=[

View File

@ -27,6 +27,15 @@ class TestPack(unittest.TestCase):
data = os.urandom(10) data = os.urandom(10)
self.assertRaises(exceptions.InvalidKastenTypeLength, pack.pack, data, 'aaaaa', 1) self.assertRaises(exceptions.InvalidKastenTypeLength, pack.pack, data, 'aaaaa', 1)
def test_invalid_enc_mode(self):
data = os.urandom(10)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', None)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', "100")
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', 100)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', -1)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', -5)
self.assertRaises(exceptions.InvalidEncryptionMode, pack.pack, data, 'txt', "test")
unittest.main() unittest.main()