mirror of https://github.com/nucypher/nucypher.git
Msgpack to pack any objects in db
parent
ddd7a6d849
commit
7f03612611
|
@ -1,5 +1,6 @@
|
|||
import appdirs
|
||||
import lmdb
|
||||
import msgpack
|
||||
import os.path
|
||||
|
||||
CONFIG_APPNAME = 'nucypher-kms'
|
||||
|
@ -19,7 +20,7 @@ class DB(object):
|
|||
|
||||
def __setitem__(self, key, value):
|
||||
with self.db.begin(write=True) as tx:
|
||||
tx.put(key, value)
|
||||
tx.put(key, msgpack.dumps(value))
|
||||
|
||||
def __getitem__(self, key):
|
||||
with self.db.begin(write=False) as tx:
|
||||
|
@ -27,7 +28,7 @@ class DB(object):
|
|||
if result is None:
|
||||
raise KeyError(key)
|
||||
else:
|
||||
return result
|
||||
return msgpack.loads(result)
|
||||
|
||||
def __delitem__(self, key):
|
||||
with self.db.begin(write=True) as tx:
|
||||
|
|
|
@ -39,7 +39,7 @@ class Client(object):
|
|||
'm-of-n reencryption not yet available')
|
||||
rekeys = rekeys[0]
|
||||
# Should specify and check signature also
|
||||
_storage[k] = {'rk': rekeys, 'algorithm': algorithm}
|
||||
_storage[k] = {b'rk': rekeys, b'algorithm': algorithm}
|
||||
|
||||
def remove_rekeys(self, pub, k):
|
||||
# Should specify and check signature also
|
||||
|
@ -51,8 +51,8 @@ class Client(object):
|
|||
:param bytes k: Address of the rekey derived from the path/pubkey
|
||||
:param bytes ekey: Encrypted symmetric key to reencrypt
|
||||
"""
|
||||
rekey = _storage[k]['rk']
|
||||
algorithm = _storage[k]['algorithm']
|
||||
rekey = _storage[k][b'rk']
|
||||
algorithm = _storage[k][b'algorithm']
|
||||
pre = crypto.pre_from_algorithm(algorithm)
|
||||
return pre.reencrypt(rekey, ekey)
|
||||
|
||||
|
|
|
@ -25,6 +25,6 @@ def test_db():
|
|||
|
||||
def test_store_dict():
|
||||
db = DB()
|
||||
db[b'x'] = {'a': 1, 'b': 2}
|
||||
assert db[b'x']['a'] == 1
|
||||
db[b'x'] = {b'a': 1, b'b': 2}
|
||||
assert db[b'x'][b'a'] == 1
|
||||
db.close()
|
||||
|
|
Loading…
Reference in New Issue