forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonpickle_util.py
57 lines (39 loc) · 1.55 KB
/
jsonpickle_util.py
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
import jsonpickle
from anoncreds.protocol.types import PublicKey, RevocationPublicKey, \
SecretKey, RevocationSecretKey, AccumulatorSecretKey
from anoncreds.protocol.utils import toDictWithStrValues, fromDictWithStrValues
DATA_KEY = 'py/integer-element'
class CommonIntegerElementHandler(jsonpickle.handlers.BaseHandler):
def flatten(self, obj, data):
data[DATA_KEY] = obj.toStrDict()
return data
def restore(self, obj):
cls = self._getClass()
return cls.fromStrDict(obj[DATA_KEY])
def _getClass(self):
raise NotImplemented
class PublicKeyHandler(CommonIntegerElementHandler):
def _getClass(self):
return PublicKey
class RevocationPublicKeyHandler(CommonIntegerElementHandler):
def _getClass(self):
return RevocationPublicKey
class SecretKeyHandler(CommonIntegerElementHandler):
def _getClass(self):
return SecretKey
class RevocationSecretKeyHandler(CommonIntegerElementHandler):
def _getClass(self):
return RevocationSecretKey
class AccumulatorSecretKeyHandler(CommonIntegerElementHandler):
def _getClass(self):
return AccumulatorSecretKey
def setUpJsonpickle():
customHandlers = [
(PublicKey, PublicKeyHandler),
(RevocationPublicKey, RevocationPublicKeyHandler),
(SecretKey, SecretKeyHandler),
(RevocationSecretKey, RevocationSecretKeyHandler),
(AccumulatorSecretKey, AccumulatorSecretKeyHandler)
]
for cls, handler in customHandlers:
jsonpickle.handlers.register(cls, handler, base=True)