-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccumulator.py
More file actions
57 lines (41 loc) · 1.42 KB
/
accumulator.py
File metadata and controls
57 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from rsa_accumulator.main import setup,add,delete
from json import JSONEncoder
import json
class Accumulator:
def __init__(self):
n,a0,s = setup()
self.n = n
self.initial_acc = a0
self.nonce = 0
self.set = s
self.current_value = a0
def __repr__(self):
return json.dumps(self.__dict__)
def addCredentials(self,credential_ids):
#Bulk add the given ids
acc_final = self.current_value
for id in credential_ids:
acc_final = add(acc_final,self.set,id,self.n)
self.nonce = self.set[id]
self.current_value = acc_final
return
def removeCrendentials(self, credential_ids):
#Bulk delete the given ids
acc_final = self.current_value
for id in credential_ids:
acc_final = delete(self.initial_acc,acc_final,self.set,id,self.n)
self.current_value=acc_final
return
def getCurrentValue(self):
#Return N and the current acc value
return self.current_value
def getNonce(self):
return self.nonce
class AccumulatorEncoder(JSONEncoder):
def default(self, object):
if isinstance(object, Accumulator):
return object.__dict__
else:
# call base class implementation which takes care of
# raising exceptions for unsupported types
return json.JSONEncoder.default(self, object)