Dummy client to use DB instead of dict

pull/24/head^2
Michael Egorov 2017-09-05 16:56:29 -07:00
parent 7f03612611
commit fe6faa0a13
1 changed files with 8 additions and 8 deletions

View File

@ -1,8 +1,6 @@
from collections import defaultdict
from nkms.db import DB
from nkms import crypto
_storage = defaultdict(dict)
class Client(object):
"""
@ -22,7 +20,9 @@ class Client(object):
"""
def __init__(self, **kw):
pass
# Dummy client stores in lmdb
# in the actual network it should be done on the server
self._storage = DB()
def store_rekeys(self, pub, k, rekeys, algorithm):
"""
@ -39,11 +39,11 @@ class Client(object):
'm-of-n reencryption not yet available')
rekeys = rekeys[0]
# Should specify and check signature also
_storage[k] = {b'rk': rekeys, b'algorithm': algorithm}
self._storage[k] = {b'rk': rekeys, b'algorithm': algorithm}
def remove_rekeys(self, pub, k):
# Should specify and check signature also
del _storage[k]
del self._storage[k]
def reencrypt(self, pub, k, ekey):
"""
@ -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][b'rk']
algorithm = _storage[k][b'algorithm']
rekey = self._storage[k][b'rk']
algorithm = self._storage[k][b'algorithm']
pre = crypto.pre_from_algorithm(algorithm)
return pre.reencrypt(rekey, ekey)