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