Browse Source

encode UUIDs as bytes.. This shrinks the pubkey string significantly...

main
John-Mark Gurney 5 years ago
parent
commit
7d6f404bcd
2 changed files with 17 additions and 7 deletions
  1. +15
    -6
      ui/cli.py
  2. +2
    -1
      ui/fixtures/genfixtures.py

+ 15
- 6
ui/cli.py View File

@@ -45,7 +45,7 @@ def _makeuuid(s):
if isinstance(s, uuid.UUID):
return s

return uuid.UUID(s)
return uuid.UUID(bytes=s)

# XXX - known issue, store is not atomic/safe, overwrites in place instead of renames

@@ -188,7 +188,7 @@ class Identity(MDBase):

def _trytodict(o):
if isinstance(o, uuid.UUID):
return 'unicode', str(o)
return 'bytes', o.bytes
try:
return 'dict', o.__to_dict__()
except Exception: # pragma: no cover
@@ -688,6 +688,15 @@ class _TestCases(unittest.TestCase):
# and that they are equal
self.assertEqual(obj, decobj)

# and in the encoded object
eobj = _asn1coder.loads(coded)

# the uuid property is a str instance
self.assertIsInstance(eobj['uuid'], str)

# and has the length of 16
self.assertEqual(len(eobj['uuid']), 16)

def test_mdbase_wrong_type(self):
# that created_by_ref can be passed by kw
obj = MetaData(created_by_ref=self.created_by_ref)
@@ -855,7 +864,7 @@ class _TestCases(unittest.TestCase):

objst.loadobj({
'type': 'metadata',
'uuid': 'c9a1d1e2-3109-4efd-8948-577dc15e44e7',
'uuid': uuid.UUID('c9a1d1e2-3109-4efd-8948-577dc15e44e7'),
'modified': datetime.datetime(2019, 5, 31, 14, 3, 10),
'created_by_ref': self.created_by_ref,
'hashes': [ 'sha256:91751cee0a1ab8414400238a761411daa29643ab4b8243e9a91649e25be53ada' ],
@@ -885,11 +894,11 @@ class _TestCases(unittest.TestCase):

self.assertEqual(len(objs), len(objst))

self.assertEqual(objs['created_by_ref'], str(self.created_by_ref))
self.assertEqual(objs['created_by_ref'], self.created_by_ref.bytes)

for i in objs['objects']:
i['created_by_ref'] = uuid.UUID(i['created_by_ref'])
i['uuid'] = uuid.UUID(i['uuid'])
i['created_by_ref'] = uuid.UUID(bytes=i['created_by_ref'])
i['uuid'] = uuid.UUID(bytes=i['uuid'])
self.assertEqual(objst.by_id(i['uuid']), i)

testfname = os.path.join(self.tempdir, 'test.txt')


+ 2
- 1
ui/fixtures/genfixtures.py View File

@@ -1,6 +1,7 @@
import pasn1
import cli
import datetime
import uuid

persona = cli.Persona()
persona.generate_key()
@@ -10,7 +11,7 @@ map(objst.loadobj,
[
{
'type': 'metadata',
'uuid': '3e466e06-45de-4ecc-84ba-2d2a3d970e96',
'uuid': uuid.UUID('3e466e06-45de-4ecc-84ba-2d2a3d970e96'),
'created_by_ref': cbr,
'modified': datetime.datetime(2019, 5, 31, 14, 5, 3),
'dc:creator': [ u'John-Mark Gurney' ],


Loading…
Cancel
Save