bump version, added support for custom args to generator auto validator in Kasten

This commit is contained in:
Kevin Froman 2020-12-07 14:47:02 +00:00
parent 3007e5aa9a
commit 663976924d
7 changed files with 31 additions and 12 deletions

View File

@ -2,6 +2,10 @@
This project uses Semantic Versioning This project uses Semantic Versioning
## 0.1.0
+ Added custom args support to kasten auto check
## 0.0.0 ## 0.0.0
Initial release Initial release

View File

@ -46,6 +46,10 @@ class KastenMimcGenerator:
@staticmethod @staticmethod
def validate_id(hash: KastenChecksum, packed_bytes: KastenPacked, rounds = 5000) -> None: def validate_id(hash: KastenChecksum, packed_bytes: KastenPacked, rounds = 5000) -> None:
try:
hash = int.from_bytes(hash, byteorder="big")
except TypeError:
pass
if not vdf_verify(packed_bytes, hash, rounds): if not vdf_verify(packed_bytes, hash, rounds):
raise InvalidID raise InvalidID
return None return None

View File

@ -26,20 +26,25 @@ class Kasten:
id: KastenChecksum, id: KastenChecksum,
packed_bytes: KastenPacked, packed_bytes: KastenPacked,
generator: 'KastenBaseGenerator', # noqa generator: 'KastenBaseGenerator', # noqa
auto_check_generator = True): # noqa *additional_generator_args,
if auto_check_generator: auto_check_generator=True,
generator.validate_id(id, packed_bytes) **additional_generator_kwargs): # noqa
self.id = id self.id = id
self.generator = generator self.generator = generator
header, data = packed_bytes.split(b'\n', 1) header, data = packed_bytes.split(b'\n', 1)
header = unpackb(header, strict_map_key=True) header = unpackb(header, strict_map_key=True)
self.header = header self.header = header
self.data = data self.data = data
self.additional_generator_args = list(additional_generator_args)
self.additional_generator_kwargs = dict(additional_generator_kwargs)
if auto_check_generator:
self.check_generator()
def check_generator(self, generator=None): def check_generator(self, generator=None):
packed = self.get_packed() packed = self.get_packed()
if generator is None: if generator is None:
self.generator.validate_id(self.id, packed) self.generator.validate_id(
self.id, packed, *self.additional_generator_args, **self.additional_generator_kwargs)
else: else:
generator(self.id, packed) generator(self.id, packed)

View File

View File

@ -1,6 +0,0 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --generate-hashes --output-file=requirements.txt requirements.in
#

View File

@ -6,11 +6,11 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read() long_description = f.read()
setup(name='kasten', setup(name='kasten',
version='0.0.7', version='0.1.0',
description='Efficient, secure data serialization format with extensibility.', description='Efficient, secure data serialization format with extensibility.',
author='Kevin Froman', author='Kevin Froman',
author_email='beardog@mailbox.org', author_email='beardog@mailbox.org',
url='https://chaoswebs.net', url='https://git.voidnet.tech/kev/kasten',
packages=find_packages(exclude=['contrib', 'docs', 'tests']), packages=find_packages(exclude=['contrib', 'docs', 'tests']),
python_requires='>3.6.0', python_requires='>3.6.0',
install_requires=['msgpack', 'mimcvdf>=1.1.0'], install_requires=['msgpack', 'mimcvdf>=1.1.0'],

View File

@ -4,6 +4,7 @@ import mimcvdf
from kasten import exceptions from kasten import exceptions
from kasten.generator import KastenMimcGenerator from kasten.generator import KastenMimcGenerator
from kasten import Kasten
class TestMimcGenerator(unittest.TestCase): class TestMimcGenerator(unittest.TestCase):
@ -29,4 +30,15 @@ class TestMimcGenerator(unittest.TestCase):
self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, invalid) self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, invalid)
self.assertEqual(K.get_packed(), k) self.assertEqual(K.get_packed(), k)
def test_mimc_generator_kasten_auto_validate(self):
k = b'\x93\xa3txt\x01\xce^\x97\xe3\xdc\ntest'
K = KastenMimcGenerator.generate(k, 1000)
Kasten(int.from_bytes(K.id, byteorder="big"), K.get_packed(), KastenMimcGenerator, *[1000])
self.assertRaises(
exceptions.InvalidID,
Kasten,
int.from_bytes(K.id, byteorder="big"), K.get_packed(), KastenMimcGenerator, *[100]
)
unittest.main() unittest.main()