bump version, added support for custom args to generator auto validator in Kasten
This commit is contained in:
parent
3007e5aa9a
commit
663976924d
@ -2,6 +2,10 @@
|
||||
|
||||
This project uses Semantic Versioning
|
||||
|
||||
## 0.1.0
|
||||
|
||||
+ Added custom args support to kasten auto check
|
||||
|
||||
## 0.0.0
|
||||
|
||||
Initial release
|
||||
|
@ -46,6 +46,10 @@ class KastenMimcGenerator:
|
||||
|
||||
@staticmethod
|
||||
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):
|
||||
raise InvalidID
|
||||
return None
|
||||
|
@ -26,20 +26,25 @@ class Kasten:
|
||||
id: KastenChecksum,
|
||||
packed_bytes: KastenPacked,
|
||||
generator: 'KastenBaseGenerator', # noqa
|
||||
auto_check_generator = True): # noqa
|
||||
if auto_check_generator:
|
||||
generator.validate_id(id, packed_bytes)
|
||||
*additional_generator_args,
|
||||
auto_check_generator=True,
|
||||
**additional_generator_kwargs): # noqa
|
||||
self.id = id
|
||||
self.generator = generator
|
||||
header, data = packed_bytes.split(b'\n', 1)
|
||||
header = unpackb(header, strict_map_key=True)
|
||||
self.header = header
|
||||
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):
|
||||
packed = self.get_packed()
|
||||
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:
|
||||
generator(self.id, packed)
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile --generate-hashes --output-file=requirements.txt requirements.in
|
||||
#
|
4
setup.py
4
setup.py
@ -6,11 +6,11 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
|
||||
long_description = f.read()
|
||||
|
||||
setup(name='kasten',
|
||||
version='0.0.7',
|
||||
version='0.1.0',
|
||||
description='Efficient, secure data serialization format with extensibility.',
|
||||
author='Kevin Froman',
|
||||
author_email='beardog@mailbox.org',
|
||||
url='https://chaoswebs.net',
|
||||
url='https://git.voidnet.tech/kev/kasten',
|
||||
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
|
||||
python_requires='>3.6.0',
|
||||
install_requires=['msgpack', 'mimcvdf>=1.1.0'],
|
||||
|
@ -4,6 +4,7 @@ import mimcvdf
|
||||
|
||||
from kasten import exceptions
|
||||
from kasten.generator import KastenMimcGenerator
|
||||
from kasten import Kasten
|
||||
|
||||
|
||||
class TestMimcGenerator(unittest.TestCase):
|
||||
@ -29,4 +30,15 @@ class TestMimcGenerator(unittest.TestCase):
|
||||
self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, invalid)
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user